This project has moved and is read-only. For the latest updates, please go here.

Rotating a Head with an Angle Joint

Aug 5, 2009 at 4:51 AM

okay, it sort of seems like i've been asking a lot of questions around here lately, and i'm not even sure if this is the right place to ask this question, but... here goes.

i'm making a dual stick shooter type game, so i need the head of my character to rotate according to the angle of the right thumbstick. so, i connected the head to the torso via a revolute joint and an angle joint, and added a line of code in the update method to set the target angle to...

((float)Math.Atan2(Player1Controller.ThumbSticks.Right.X * player1_ThumbLookCoef , Player1Controller.ThumbSticks.Right.Y * player1_ThumbLookCoef) - MathHelper.PiOver2)

which  is the angle that the head should be moving to, according to the right thumbstick.

however, when the target angle moves between 2pi and 0 (down on the thumbstick), the head rotates up, spinning the head around and shaking the body violently. this will not do, but i cannot for the life of me think of any sort of formula to move the target angle between 2pi and 0 smoothly. does anybody have any thoughts as to fix this? i can always just update the rotation value of the body, but it's kinda odd looking, and i read somewhere that's not exactly the correct way to do things, is that true?

Aug 5, 2009 at 1:14 PM

The problem is (if I understood you correctly) that you are using the physics engine for something it wasnt built for.

What I would do I would attach the head to the body with a simple pin joint, so you wont have to keep track of the heads position manually, but rotate the sprite which represents the head outside of the physics engine.