Unable to get desired rotation (FixedAngleJoint)

Mar 27, 2009 at 9:20 AM
I am attempting to use a single FixedAngleJoint, anchored to the center of my rectangle, to rotate the rectangle 45 degrees either way. Rotation to the right works great, but no matter what I do, I can't get it to rotate to the left without the rectangle absolutely going out of control. It is going out of control because I can't get it to rotate from -45 degrees (~5.8 radians) back to 0 degrees correctly.

Here's my code:

 private bool DoRightTrigger(InputState input)
        {
            if (input.CurrentGamePadState.Triggers.Right > 0.1f)
            {
                State = PaddleState.RotateRight;

                if (input.CurrentGamePadState.Triggers.Right > 0.96f)
                    _rectangleBody.Rotation = 0.785f;

                else
                    _pivotJoint.TargetAngle = 0.785f * input.CurrentGamePadState.Triggers.Right;
                return false;
            }

            else if(State == PaddleState.RotateRight)
            {
                _pivotJoint.TargetAngle = 0;
                if (_rectangleBody.Rotation < 0.01)
                {
                    _rectangleBody.Rotation = 0;
                    State = PaddleState.NoRotate;
                    return true;
                }
                return false;
            }
            return true;
        }

        private void DoLeftTrigger(InputState input)
        {
            if (input.CurrentGamePadState.Triggers.Left > 0.1f)
            {
                State = PaddleState.RotateLeft;

                if (input.CurrentGamePadState.Triggers.Left > 0.96f)
                    _rectangleBody.Rotation = 5.8f;

                else
                    _pivotJoint.TargetAngle = 5.8f * input.CurrentGamePadState.Triggers.Left;

            }

            else if(State == PaddleState.RotateLeft)
            {
                _pivotJoint.TargetAngle = 6.2f;
                if (_rectangleBody.Rotation > 6)
                {
                    _rectangleBody.Rotation = 0;
                    State = PaddleState.NoRotate;
                }
            }  
        
        }

        public void HandleGamePadInput(InputState input)
        {
            Vector2 force = 1000 * input.CurrentGamePadState.ThumbSticks.Left;
            force.Y = -force.Y;
            _rectangleBody.ApplyForce(force);


            switch (State)
            {
                case PaddleState.NoRotate:
                    if(DoRightTrigger(input))
                        DoLeftTrigger(input);
                    bfreak;
                case PaddleState.RotateRight:
                    DoRightTrigger(input);
                    break;
                case PaddleState.RotateLeft:
                    DoLeftTrigger(input);
                    break;
            }


            

        }

I really really need some help here. I would love to use this engine in my project, but this is a fundamental behavior for my rectangle.

Thanks
~Eric
Mar 27, 2009 at 6:26 PM
Hi! I had a similar problem some time ago, check this thread http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=50208 and see if it can help you...
In the 6th post i described the crazy rotation happening in my project. My solution was just set body.rotation manually and set body.angularvelocity to 0 every frame.
Good luck!
Coordinator
Mar 27, 2009 at 9:54 PM
The FixedAngleJoint rotates all the way around when the angle reach a certain limit. This is expected behavior.
To have a greater control over the rotation, just set the rotation manually or use ApplyTorque() on the Body class. The Rotation property sets all the correct setting such as revolutions and totalRotation.
Mar 28, 2009 at 10:57 AM
That wasn't exactly what I needed, but it got me thinking, problem solved!! If anyone wants to see the code I used, let me know, I'll keep watching this discussion.