Revolute joint as Spring jitter problem

Topics: Developer Forum
Jul 25, 2011 at 5:55 AM

Hello,

This is my first post to the forum, however; I have gleaned a wealth of knowledge from many of the contributors here. Thank You.

 I am using a revolute joint as an angular spring:

 

//Initialized in LoadContent()

            joint = JointFactory.CreateFixedRevoluteJoint(_world, triangle, new Vector2(1.4f, 1.4f), new Vector2(6.0f + 1.4f, simulatedHeight));
            joint.MaxMotorTorque = 0f;
            joint.MotorEnabled = true;

//In Update()
            joint.MaxMotorTorque = Math.Abs((joint.JointAngle * 100) + (joint.JointSpeed * 10));
            joint.MotorSpeed = joint.JointAngle < 0 ? -10000 : 10000;

Basically, I'm applying Hooke's law with damping. However, when joint.JointAngle converges to 0.0f,
joint.MaxMotorTorque spikes causing a jitter in the "triangle" body.
I have tried:
if (joint.JointSpeed < 0.001f && joint.JointSpeed > -0.001f)
            {                
                joint.MotorSpeed = 0;
            }

Which sort of works, but feels hackish. Anyone have a better way to create an angular spring in this sense?
I have posted a video to give a better visual of what is actually going on. The video does not have the previous
"if" statement included in the code.

http://youtu.be/DpmVFU2J3sE
Jul 26, 2011 at 3:54 AM

Well, I figured it out! I was declaring some of my vertices in the polygon creation completely wrong! Works like a charm now.