• Advertisement

Archived

This topic is now archived and is closed to further replies.

Moving objects along a line

This topic is 5216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, Pretty basic question. How do you make thing move along a line given an angle (either in deg or rad, dont mind). I''ve programmed a particle system but it only has the ability to move in a preprogrammed direction (up, down, left, right). I would like to be able to move in any direction. Just a forumla or pseudo code would be cool Thanks Phil Price™: Better than cool - uber cool.

Share this post


Link to post
Share on other sites
Advertisement
angle is in radians

VECTOR2D direction(sinf(angle) * speed,cosf(angle) * speed);

particlePos += direction * timeDelta;


My Site

[edited by - Quasar3D on November 9, 2003 11:08:14 AM]

Share this post


Link to post
Share on other sites
Well ... vector2D means two data (x,y).

In this exemple, the variation of x, deltaX is equal to
sinf(angle) * speed and deltaY is equal to cosf(angle) * speed.

To get the new position,

x = x + (deltaX * deltaTime);
y = y + (deltaY * deltaTime);

You'll need at least some basic vector maths if you want to make games, reading a good book on algebra may be in order.

Hope this clarifies things a bit.

[edited by - Ithyl_Chantresonge on November 9, 2003 12:19:23 PM]

Share this post


Link to post
Share on other sites
I love when you give 'complex' examples to someone who obviously is not ready for it.

Here's a more simple example;



//in the init particle code

posx = particlegenerator_x;
posy = particlegenerator_y;

dx = getrandomnum_int();
dy = getrandonnum_int();
...
//in the draw particle code

putpixel (posx, poxy, color);
...
//in the update particle code

posx += dx;
posy += dy + gravity;






[edited by - nonnus29 on November 9, 2003 1:38:34 PM]

Share this post


Link to post
Share on other sites
Cheers Ithyl, i thought it was a mixture of cos() and sin() but wasnt sure. Agreed i need to brush up on my maths, its been 4 years since i did it seriously.

nonnus29, thanks for the reply, but.. I have to say it was far too simple, i asked how to move things across a straight line given an angle, but how to make my particles randomly move around in a linear fashion. But hey its all good I''ve already written effects like fire, explosions, fireworks, smoke, i just needed to logic behind changing the angle

Peace out.

Share this post


Link to post
Share on other sites

  • Advertisement