I am trying to find out a formula that calculates the actual position of a player using his speed and a destination position.
These are the informations I have:
- Vector3 (X,Y,Z) : Current position
- Vector3 (X,Y,Z) : Destination position
- float : Speed
I can manage to calculate the angle between these two vectors, but I can't find an efficient formula to calculate the exact position using the speed at each loop. Do you have an idea?
EDIT*
I finally found a formula, but it's not really working as I want...
private void WalkNew()
{
float speed = 0.1f;
float distX = this.DestinationPosition.X - this.Position.X;
float distZ = this.DestinationPosition.Z - this.Position.Z;
float distance = (float)Math.Sqrt((distX * distX) + (distZ * distZ)); // distance between A and B positions
float time = distance / speed;
float currentTime = Time.GetTickFrom(this.lastMoveTime);
this.lastMoveTime = Time.GetTick();
float percentage = currentTime / time;
if (this.Position.IsInCircle(this.DestinationPosition, 0.1f))
{
// We arrived
}
else
{
this.Position.X += distX / percentage;
this.Position.Z += distZ / percentage;
}
}
Any thoughts about this formula ?
Thanks