• Create Account

## Moving an object along a 2D vector

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1StJohnOwasso  Members

100
Like
0Likes
Like

Posted 23 July 2010 - 11:57 AM

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

### #2StJohnOwasso  Members

100
Like
0Likes
Like

Posted 23 July 2010 - 12:07 PM

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.

### #3scgames  Members

2082
Like
0Likes
Like

Posted 23 July 2010 - 12:32 PM

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;

### #4StJohnOwasso  Members

100
Like
0Likes
Like

Posted 23 July 2010 - 12:43 PM

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!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.