# Moving a joint to an angle problem.

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

## Recommended Posts

Hey all, I'm currently working on my first open source game (http://ragdollcombat.sourceforge.net) implementing the Newton Game Dynamics library (though this is probably a generic problem and not specific to any library) and I need some help with physics calculations as i'm very new to computer game physics, sorry if this post is a bit long but i'll try and explain my problem as best I can. Note: Child body is the body the joint is attaching and parent body is the body the joint is attached to, for example the parent body of the elbow is the upper arm and the child body is the forearm. The effect i'm trying to achieve is that a joint, in this case a ball joint, can be given the rotation it should be at (the rotation of the child body relative to the parent body) and then will move there by applying the correct torque to the child body on every time step of the physics simulation. So I can animate everything in the game using nothing but physics. The system i'm using right now handles all rotations in euler angles in radians. Here are the Newton physics engine procedures which i'm using: BallJointGetAngle gets the euler angles of rotation of the joint. BallJointGetOmega gets the angular velocity of the rotation of the joint. BodyGetMassMatrix gets the inertia matrix of the mass of the body, specifically ixx, iyy and izz. WorldGetTimestep returns the amount time has been stepped by. BodySetTorque sets the torque vector being applied to the body. The algorithm i'm using is a simple spring formula for each of the euler angles of rotation, this procedure is called at every timestep of the simulation: k = 20 <-- spring constant b = 0.5 <-- damping constant moveTo <-- the angle the joint should move to BallJointGetAngle(joint, angle) BallJointGetOmega(joint, omega) BodyGetMassMatrix(body, mass, ixx, iyy, izz) timestep = WorldGetTimeStep(world) torque.X = (moveTo.X - angle.X) * k - (omega.X * b) * ixx / timestep torque.Y = (moveTo.Y - angle.Y) * k - (omega.Y * b) * iyy / timestep torque.Z = (moveTo.Z - angle.Z) * k - (omega.Z * b) * izz / timestep BodySetTorque(body, torque) My problem is that whenever I set more than one of the moveTo angles to something other than zero the system goes crazy and starts to jerk around and spin faster and faster. The really confusing bit is that if I set just one of the moveTo angles to something other than zero (e.g. Pi/4) it works absolutely perfectly. I think my problem is something to do with the order euler angles are applied in or just me not understanding euler angles properly :(. If anyone has a way of fixing this or a better way of achieving the same effect, like using quaternions (which I don't know about but would be more than willing to learn if it will fix the problem) it would be amazingly appreciated and would save my project. Will

• ### 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
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×