Jump to content
  • Advertisement


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


Following a Line with a Sprite

This topic is 5640 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 All I am curious if there is a algo to make a sprite follow a line (ie move from point1 to point2) which can be run real time (taking into account frame speed and a movement speed) or is it best to generate the x,y cords of everypoint on the line (gives line length points) and the movement amount is basically calculated as an offset into the line point array.. i hope that makes sence.. Cheers Chris Jumpman - Under Construction

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Use time based movement and just have waypoints (x,z) and have the sprite follow the terrain''s y-axis height.

Share this post

Link to post
Share on other sites
Im not so sure what you mean but if you want a sprite to follow a line just create a normalized vector of the two points then multiply it by the speed and then add the vector multiplied by delta time to your sprites coords every frame.
In code that would be something like this:
Say we have Points A(a1, a2, a3) and B(b1, b2, b3)

struct Vector
void CreateNormalizedFromPoints(float x1, float y1, float z1,
float x2, float y2, float z2)
x = x2-x1;
y = y2-y1;
z = z2-z1;

//Normalize(setting length to 1 using pythagoras)
float length2d = sqrt(x*x+y*y);
float length = sqrt(length2d*length2d+z*z);


void main()
Vector dir;

//warning pseudocode



My Website

[edited by - CProgrammer on July 3, 2003 3:38:17 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!