Page 1 of 1

Ragdoll wobbeling

Posted: Mon Sep 30, 2013 4:02 pm
by grobi
Hi,
I stated playing with ragdolls I set one up based on the actionfiguredemo and unfortunateguydemo but I put the angularmotors of the joints into servo mode to make the limbs controllable by setting a goal, now when the ragdoll tips over and falls onto the ground it starts wobbeling and shaking, the limbs are twisting and turning which can not be right.

Code: Select all

            #region body
	    body = new Box(new Vector3(0, -4.5f, 0), 1.5f, 2, 1, 10);
            space.Add(body);
            #endregion
            
            #region head
            head = new Sphere(body.Position + new Vector3(0, 2, 0), .5f, 5);
            space.Add(head);
            
            //Connect the head to the body.
            space.Add(new BallSocketJoint(body, head, head.Position + new Vector3(0, -.9f, 0)));
            //Angular motors can be used to simulate friction when their goal velocity is 0.
            var angularMotor = new AngularMotor(body, head);
            angularMotor.Settings.MaximumForce = 150; //The maximum force of 'friction' in this joint.
            space.Add(angularMotor);
			#endregion
			
            #region left arm
            //Make the first arm.
            upperArmLeft = new Box(body.Position + new Vector3(-1.6f, .8f, 0), 1, .5f, .5f, 5);
            space.Add(upperArmLeft);
            
            lowerArmLeft = new Box(upperArmLeft.Position + new Vector3(-1.4f, 0, 0), 1, .5f, .5f, 5);
            space.Add(lowerArmLeft);

            //Connect the body to the upper arm.
            space.Add(new BallSocketJoint(body, upperArmLeft, upperArmLeft.Position + new Vector3(.7f, 0, 0)));
            space.Add(new EllipseSwingLimit(body, upperArmLeft, Vector3.Up, MathHelper.PiOver2, MathHelper.PiOver4 * 3));
 			var twistLimit = new TwistLimit(body, upperArmLeft, Vector3.Up, Vector3.Up, -MathHelper.PiOver4 / 2, MathHelper.PiOver4);
			twistLimit.SpringSettings.StiffnessConstant = 100;
			twistLimit.SpringSettings.DampingConstant = 100;
			space.Add(twistLimit);
			
            shoulderLeftMotor = new AngularMotor(body, upperArmLeft);
            shoulderLeftMotor.Settings.MaximumForce = 250;
            shoulderLeftMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(shoulderLeftMotor);
            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(body, upperArmLeft, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
            
            //Connect the upper arm to the lower arm.
            //space.Add(new BallSocketJoint(upperArmLeft, lowerArmLeft, upperArmLeft.Position + new Vector3(-.7f, 0, 0)));
            var elbow = new SwivelHingeJoint(upperArmLeft, lowerArmLeft, upperArmLeft.Position + new Vector3(-.7f, 0, 0), Vector3.ForwardRH);
			//Forearm can twist a little.
			elbow.TwistLimit.IsActive = true;
			elbow.TwistLimit.MinimumAngle = -MathHelper.PiOver4 / 2;
			elbow.TwistLimit.MaximumAngle = MathHelper.PiOver4 / 2;
			elbow.TwistLimit.SpringSettings.DampingConstant = 100;
			elbow.TwistLimit.SpringSettings.StiffnessConstant = 100;
			//The elbow is like a hinge, but it can't hyperflex.
			elbow.HingeLimit.IsActive = true;
			elbow.HingeLimit.MinimumAngle = 0;
			elbow.HingeLimit.MaximumAngle = MathHelper.Pi * .7f;
			space.Add(elbow);
            
            elbowLeftMotor = new AngularMotor(upperArmLeft, lowerArmLeft);
            elbowLeftMotor.Settings.MaximumForce = 150;
            elbowLeftMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(elbowLeftMotor);
            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(upperArmLeft, lowerArmLeft, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
			#endregion
			
			#region right arm
            //Make the second arm.
            upperArmRight = new Box(body.Position + new Vector3(1.6f, .8f, 0), 1, .5f, .5f, 5);
            space.Add(upperArmRight);

            lowerArmRight = new Box(upperArmRight.Position + new Vector3(1.4f, 0, 0), 1, .5f, .5f, 5);
            space.Add(lowerArmRight);

            //Connect the body to the upper arm.
            space.Add(new BallSocketJoint(body, upperArmRight, upperArmRight.Position + new Vector3(-.7f, 0, 0)));
            space.Add(new EllipseSwingLimit(body, upperArmRight, Vector3.Up, MathHelper.PiOver2, MathHelper.PiOver4 * 3));
 			var twistLimit = new TwistLimit(body, upperArmRight, Vector3.Up, Vector3.Up, -MathHelper.PiOver4 / 2, MathHelper.PiOver4);
			twistLimit.SpringSettings.StiffnessConstant = 100;
			twistLimit.SpringSettings.DampingConstant = 100;
			space.Add(twistLimit);
            //Angular motors can be used to simulate friction when their goal velocity is 0.
            shoulderRightMotor = new AngularMotor(body, upperArmRight);
            shoulderRightMotor.Settings.MaximumForce = 250; //The maximum force of 'friction' in this joint.
            shoulderRightMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(shoulderRightMotor);
			BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(body, upperArmRight, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
			
            //Connect the upper arm to the lower arm.
            //space.Add(new BallSocketJoint(upperArmRight, lowerArmRight, upperArmRight.Position + new Vector3(.7f, 0, 0)));
            var elbow = new SwivelHingeJoint(upperArmRight, lowerArmRight, upperArmRight.Position + new Vector3(.7f, 0, 0), Vector3.ForwardRH);
			//Forearm can twist a little.
			elbow.TwistLimit.IsActive = true;
			elbow.TwistLimit.MinimumAngle = -MathHelper.PiOver4 / 2;
			elbow.TwistLimit.MaximumAngle = MathHelper.PiOver4 / 2;
			elbow.TwistLimit.SpringSettings.DampingConstant = 100;
			elbow.TwistLimit.SpringSettings.StiffnessConstant = 100;
			//The elbow is like a hinge, but it can't hyperflex.
			elbow.HingeLimit.IsActive = true;
			elbow.HingeLimit.MinimumAngle = 0;
			elbow.HingeLimit.MaximumAngle = MathHelper.Pi * .7f;
			space.Add(elbow);
            
            elbowRightMotor = new AngularMotor(upperArmRight, lowerArmRight);
            elbowRightMotor.Settings.MaximumForce = 150;
            elbowRightMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(elbowRightMotor);
			BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(upperArmRight, lowerArmRight, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);            
			#endregion
            
			#region left leg
            //Make the first leg.
            upperLegLeft = new Box(body.Position + new Vector3(-.6f, -2.1f, 0), .5f, 1.3f, .5f, 8);
            space.Add(upperLegLeft);

            lowerLegLeft = new Box(upperLegLeft.Position + new Vector3(0, -1.7f, 0), .5f, 1.3f, .5f, 8);
            space.Add(lowerLegLeft);

            //Connect the body to the upper leg.
            space.Add(new BallSocketJoint(body, upperLegLeft, upperLegLeft.Position + new Vector3(0, .9f, 0)));
            //Angular motors can be used to simulate friction when their goal velocity is 0.
            hipLeftMotor = new AngularMotor(body, upperLegLeft);
            hipLeftMotor.Settings.MaximumForce = 350; //The maximum force of 'friction' in this joint.
            hipLeftMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(hipLeftMotor);
            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(body, upperLegLeft, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
            
            //Connect the upper leg to the lower leg.
            space.Add(new BallSocketJoint(upperLegLeft, lowerLegLeft, upperLegLeft.Position + new Vector3(0, -.9f, 0)));
            kneeLeftMotor = new AngularMotor(upperLegLeft, lowerLegLeft);
            kneeLeftMotor.Settings.MaximumForce = 250;
            kneeLeftMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(kneeLeftMotor);
            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(upperLegLeft, lowerLegLeft, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
			#endregion
			
			#region right leg
            //Make the second leg.
            upperLegRight = new Box(body.Position + new Vector3(.6f, -2.1f, 0), .5f, 1.3f, .5f, 8);
            space.Add(upperLegRight);

            lowerLegRight = new Box(upperLegRight.Position + new Vector3(0, -1.7f, 0), .5f, 1.3f, .5f, 8);
            space.Add(lowerLegRight);

            //Connect the body to the upper leg.
            space.Add(new BallSocketJoint(body, upperLegRight, upperLegRight.Position + new Vector3(0, .9f, 0)));
            //Angular motors can be used to simulate friction when their goal velocity is 0.
            hipRightMotor = new AngularMotor(body, upperLegRight);
            hipRightMotor.Settings.MaximumForce = 350; //The maximum force of 'friction' in this joint.
            hipRightMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(hipRightMotor);
			BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(body, upperLegRight, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
			
            //Connect the upper leg to the lower leg.
            space.Add(new BallSocketJoint(upperLegRight, lowerLegRight, upperLegRight.Position + new Vector3(0, -.9f, 0)));
            kneeRightMotor = new AngularMotor(upperLegRight, lowerLegRight);
            kneeRightMotor.Settings.MaximumForce = 250;
            kneeRightMotor.Settings.Mode = MotorMode.Servomechanism;
            space.Add(kneeRightMotor);
            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(upperLegRight, lowerLegRight, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase);
            #endregion
how can i prevent such behaviour?

thx Grobi

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 6:24 pm
by Norbo
I cannot reproduce any wobbling/shaking behavior when I put that code in the latest BEPUphysicsDemos. It seems to work as expected.

What version do you see the problem in? I would recommend moving to the latest dependency free version regardless, but it would be good to pin down to the source.

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 6:51 pm
by grobi
i use the latest sharpdx fork compiled against latest sharpdx.dll and unsigned

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 6:58 pm
by grobi
think I found it, it does not happen when I update the space with space.Update() and not using space.Update(deltaTime);

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 7:37 pm
by Norbo
It seems to be related to the fact that SharpDX 2.5 swapped some quaternion math around. Does it still happen with this update?

Note that the dependency free version is far ahead of the SharpDX branch. If you want the changes included in the last year and then some, switching over would be a good idea. I'll update the SharpDX branch to match once v1.3.0 is 'properly' released, but that will be a little while yet.

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 8:14 pm
by grobi
Thanks Norbo,
by latest dependency free version you mean the current sourcecode of the standard bepuphysics 1.2 Version located here : http://bepuphysics.codeplex.com/SourceControl/latest ?

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 8:20 pm
by Norbo
by latest dependency free version you mean the current sourcecode of the standard bepuphysics 1.2 Version located here :
The main source, yes. It's not v1.2.0 specifically, though. It's just the latest state of development. It's currently on v1.3.0.

Re: Ragdoll wobbeling

Posted: Mon Sep 30, 2013 8:21 pm
by grobi
Problem is gone after your update in sharpdx fork, thanks a lot!!!