Followers 0

Moving an object along a 2D vector

3 posts in this topic

I know this is really basic, but I can't remember how I've done it before, and my drive just got reimaged and I've lost most of my projects.

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
0

Share on other sites
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.
0

Share on other sites
Quote:
 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.
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.)

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;
0

Share on other sites
Thank you so much!! I contacted an old dev team member and looked through some old source and that's exactly what I had done before. Thanks again!
0

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account