Public Group

#### Archived

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

# Moving objects along a line

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

## 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 on other sites

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 on other sites
Does this return both the X and Y? How would i calculate these seperatly?

##### 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 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 codeposx = particlegenerator_x;posy = particlegenerator_y;dx = getrandomnum_int();dy = getrandonnum_int();...//in the draw particle codeputpixel (posx, poxy, color);...//in the update particle codeposx += dx;posy += dy + gravity;

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

##### 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.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633314
• Total Posts
3011325
• ### Who's Online (See full list)

There are no registered users currently online

×