Following a set of points?
- by user1010005
Lets assume that i have a set of path that an entity should follow :
const int Paths = 2
Vector2D<float> Path[Paths] = { Vector2D(100,0),Vector2D(100,50) };
Now i define my entity's position in a 2D vector as follows :
Vector2D<float> FollowerPosition(0,0);
And now i would like to move the "follower" to the path at index 1 :
int PathPosition = 0; //Start with path 1
Currently i do this :
Vector2D<float>& Target = Path[PathPosition];
bool Changed = false;
if (FollowerPosition.X < Target.X) FollowerPosition.X += Vel,Changed = true;
if (FollowerPosition.X > Target.X) FollowerPosition.X -= Vel,Changed = true;
if (FollowerPosition.Y < Target.Y) FollowerPosition.Y += Vel;,Changed = true;
if (FollowerPosition.Y > Target.Y) FollowerPosition.Y -= Vel,Changed = true;
if (!Changed)
{
PathPosition = PathPosition + 1;
if (PathPosition > Paths) PathPosition = 0;
}
Which works except for one little detail : The movement is not smooth!! ...So i would like to ask if anyone sees anything wrong with my code.
Thanks and sorry for my english.