Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted (edited)

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.

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.

Guest
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 link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

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