Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to develop a simple 2D space game with no friction using . In the game, I have several planets which all applies forces to the player according to Newton's law of universal gravitation. Once the player is close enough to a planet, I need to put him in orbit. I do so, by creating a pivot joint between the planet and the player. From the player's liner velocity, I compute the joint's motor speed in order to achieve an as much as possible smooth cyclic rotation around the planet.

The solution, which might not be optimal (in future versions I would like to avoid completely the joint), so far is working but I'm not able to determine correctly the joint's rotation direction. The rotation of the player around the planet should be CW or CCW depending on the player's angle of approach. How do I compute that ?

Thanks !

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'd construct a line from the centre of the planet to the ship, and also calculate a point which is the ship's position + ship's velocity.

From there you can use a standard test to find out which side of the line the point is on, which tells you if it should orbit clockwise or anticlockwise.

share|improve this answer
    
Pretty clear ! I've tested it and it is working as expected. Thank you very much ! –  slavikos Jan 12 '13 at 22:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.