Public Group

# Math little problem

This topic is 4558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm reviewing my math for the moment, but I'm stuck on this simple problem. The data at my disposal : My location inside a vector called Location. My direction inside a vector called Direction. The distance of the move called Distance How can I compute my new location based on those data : NewLocation = Location where I apply a move of Distance unit in the direction Direction. I know it's quite easy, but I really don't know how to do it :( Tx you for your help !

##### Share on other sites
Is distance a scalar?

If so, the equation is exactly as you described:

NewLocation = location + distance * direction.

##### Share on other sites
If you don't want to overload the + and * operators, it would be
for(int i=0;i<2;i++) NewLocation = Location + Distance * Direction;

##### Share on other sites
Tx you for your help !

I suppose that my Direction vector must by normalized for working ?

##### Share on other sites
Yes... assuming your vectors use floats. If they are ints, a normalized direction vector won't work too good.

##### Share on other sites
If you're going to just multiply the distance by the Direction vector, yes, it must be normalized.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634083
• Total Posts
3015402
×