# Particle Effect Math

## Recommended Posts

Hi there!

I'm trying to figure out how to make particles move around in specific ways, the only problem being is that I am very bad at math. (As in I have a major problems learning when it comes to specifically mathematics) I understand Java and know how to program, got a 4 on an AP Comp Sci A test (no idea if that means anything). I just seem to struggle with the Math side of things no matter how hard I try to understand it. I suppose i'll try to explain what i'm trying to do with the particles and perhaps someone could explain to me exactly what to do / understand how to do it so I can apply the knowledge in the future.

List of Effects i'm trying to accomplish for my mod:

- Vacuum Effect (Particles spawning in random locations in a spherical radius, and moving towards a center point starting slow and rapidly picking up speed as it gets closer to the center point)

- Orbit Effect (Particles moving around in an ring like orbit, would like to cover how to rotate the axis' to make the ring turn)

- Wave Effect (Particles moving in a wavy line from Point A to point B just picture a squiggly line in 3D)

I know this is a lot to ask for, just please don't go tell me to study math or something because I'm already trying and struggle with it everyday.

Thanks!

- EmeraldJelly

P.S. I already know how to physically spawn particles at specific locations I just don't know the math / functions to manipulate them. I.E. Make them move.

##### Share on other sites

For spawning particles within a sphere, you could find randomized positions within a cube of the right size, then not use any position whose distance from the center block is greater than the radius. You can check distance from the center block by using the Pythagorean theorem (a^2 + b^2 + c^2 = d^2 for 3D).

A mock-up to find the spawning position:

```while (!valid)
{
x = ran.nextFloat(mag * 2) - mag;
y = ran.nextFloat(mag * 2) - mag;
z = ran.nextFloat(mag * 2) - mag;

if ((x*x) + (y*y) + (z*z) > (mag*mag))
{
valid = false;
}
else valid = true;
}```

As for the speed thing, I'm not sure whether or not you can change the velocity of a particle that's already spawned (at least I don't know how to). Regardless, you could set its velocity to (the radius minus the distance from the center block in x y or z) times (some scale factor to get the speeds to look good), either on spawning, or periodically if it's possible. You'll probably then have to kill the particle somehow or it'll slide off the center block when they collide. There might be a way around that, though.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

##### Share on other sites

For the orbit effect, you can use 3D polar* coordinates for both the movement in a ring as well as the rotation of that ring. The mathematics of orienting the ring, though, depend on how you want the ring to be oriented and rotated. For example, do you want it to be a vertical ring, rotated around the Y-axis? Or a horizontal ring rotated around X or Z?

With the wave, you can spawn particles slowishly along the line from A to B, step by step. With each step, you could add to an angle variable which you take the sin or cosine of. That gives you a varying value between -1 and 1, depending on how far through the line you are. You can then add that varying value to the Y coordinate you otherwise would have spawned the particle at, and the height will vary in a wave pattern. You can also multiply the varying value from the sin/cosine by a scale factor to either stretch or squish the waves.

Edit: You should also note that the Math.sin and Math.cos methods work with radians, not degrees.

*Edit2: 3D spherical. Oops.

Edited by SerpentDagger

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

##### Share on other sites

You are literally amazing, i'll try this when I get back to my code later tonight, thanks!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Recently Browsing

• No registered users viewing this page.
• ### Posts

• -Are you saturating with servers full of mods that you don't even know what to do? -Do you want to try a completely new server, with friendly staff, ranked events, fair economy and support at any time of the day? -On our server you can find: DIGITAL SHOP , PETS , MINE PVP , PVP ZONE ,QUESTS FOR ALL JOBS , SKILLS , BAR , KITS , CRATES , SPAWN END , BAZAR , PROTECTION ANTI-GRIEF/PVP , PLOTS , ETC... JOINET COMMUNITY presents the Mc.Joinet.Ro server. -The server is very much based on respect between players and most of the improvements are made based on your opinions! WE CARE VERY MUCH ABOUT THE OPINIONS OF OUR PLAYERS!  Server IP: mc.joinet.ro                                  WE ARE WAITING FOR YOU IN AS LARGE NUMBERS AS POSSIBLE
• Got this stacktrace: C:\IdeaProjects\MultiCarsForge120\client\src\main\java\me\wattguy\cars\mixin\ScreenMixin.java:14: warning: Unable to locate obfuscation mapping for @Shadow method @Shadow protected abstract <T extends GuiEventListener & Renderable & NarratableEntry> T addRenderableWidget(T arg); ^ This is not in the refmap either. What to do? It’s worth mentioning that most of it is in the refmap, but a couple of methods/fields are missing. It feels like the mappings are incomplete, how can I update them?
• Actualy, it doesn´t work again
• dynamictrees and waila are running into a conflict Make a test without waila

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...

## Important Information

By using this site, you agree to our Terms of Use.