Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

box2D how to determine currently heading vector?

4: Adsense

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.


  • You cannot reply to this topic
1 reply to this topic

#1 MARS_999   Members   

1620
Like
0Likes
Like

Posted 18 March 2013 - 01:38 AM

I have two objects in box2D and would like to use ApplyForce() on each object but add more force when they are closer to each other but apply it in the vector they are currently moving?



#2 Akaski   Members   

116
Like
0Likes
Like

Posted 18 March 2013 - 03:07 PM

You can get a vector with a length of 1 if you divide each component by the vector's length. So x1 = x/sqrt(x^2+y^2) y1 = y/sqrt(x^2+y^2)
(x and y being vector components) (also, a vector formed by these new components is called a unit vector because its length is 1)

From there, you can multiply each component by force to get the force to act in the direction of the 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.