Moving an object along a 2D vector,
Members - Reputation: 100
Posted 23 July 2010 - 11:57 AM
How would I go about moving an object along a vector in 2D space.
Example: User uses mouse input to click on the desired point to move to, and the player updates and moves to that point. I know that I need to find the vector from the destination to the player, but I am at a loss for how to move him along that vector. Thanks to all for any help given! :D
Members - Reputation: 2078
Posted 23 July 2010 - 12:32 PM
Quote:Linear interpolation of vectors isn't particularly taxing for the processor, generally speaking. (At the very least, it's unlikely to be any more taxing than any other method you might use.)
P.S. I was thinking about just doing a linear interpolation, but I think I did it in a less processor taxing way last time I had to do it.
The typical solution here would be to compute the normalized vector to the target position:
vector direction = normalize(target.position - character.position);And then for each update, move the character along this vector according to the character's speed and the current time step:
character.position += direction * character.speed * timeStep;