1
\$\begingroup\$

I'm working on a particle field system, where the particles can go from a point of the map, to another point of the map, using an angle (with sin and cos).

By now, I can calculate the vector by defining an angle using the cos and sin

float X = sin(DEGREES_TO_RADIANS(45));
float Y = cos(DEGREES_TO_RADIANS(45));

That forms a trajectory, like in this image: (Trajectory in red)

enter image description here

I need the particle to follow that trajectory, to move over that trajectory and arrive to the the vector (X,Y).

How can I translate the object ONLY over the red trajectory?

\$\endgroup\$
4
  • \$\begingroup\$ Normalize x and y by the distance travelled in one frame, and move object to location O + (tx_n, ty_n) on frame t since movement started until it reaches the target. \$\endgroup\$ Sep 12, 2013 at 4:09
  • \$\begingroup\$ Two ways: if you can sample the trajectory, key frame it using the sample points as intermediary positions OR use an integration method (Velocity Verlet since it conserves energy, is reversible in time, and accurate so you can Exactly stay on quadratic curves using any time step). But that's an overkill.. you essentially end up summing vectors.. what's the real problem you're facing? The question doesn't explain the problem.. just a vague goal. \$\endgroup\$
    – teodron
    Sep 12, 2013 at 7:09
  • \$\begingroup\$ I think the Peter comment can solve this 'problem'. I'll try later and I'll comment if it worked or not :) I think it will (Teodron) The 'problem' is the following: Imagine a particle over the (0,0) coordinate, There is a vector that starts from that point (origin) and arrives (X,Y), that makes a trajectory like in the image above, I need a particle animation that travels along that trajectory until it arrives to (X,Y), I haven't found any answer in google yet, maybe because I am a bad googler. \$\endgroup\$
    – Zumbock
    Sep 12, 2013 at 11:59
  • \$\begingroup\$ @user250783 if you move the object from the origin right into point (X,Y), then you will not see it go through any intermediary points on the red line. I.e. your frame step is always of magnitude 1.. are you sure this is what you need? \$\endgroup\$
    – teodron
    Sep 12, 2013 at 13:30

1 Answer 1

0
\$\begingroup\$

If you're asking how you can move a particle from the point 0,0 to the point X,Y. You have to first ask yourself how long that particle is going to take to get to that point. Give it a value in units per second. For instance if it takes one second then it goes 1 unit per sec, that's your speed. Multiply your speed by the vector you created with the cos/sin equation, this is your velocity vector.

Start the particle at 0,0. Then every frame you're going to update the particle's position by adding the current position of the particle with the velocity vector multiplied by the delta time (that's the time in seconds between frames). For instance at 30 fps the detla is 0.0333...

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .