Change AngleLimit dynamically

Jun 8, 2010 at 5:02 AM

Hello, I am from Taiwan and new to the Farseer Physics.

The Engine is awesome and also the Helper do ease the development.

I am trying to control a doll programmatically begin with the DemoBehaviors5(a bikini girl).

1. I try to change some properties of AngleLimitJoint after the simulation started but nothing happened.

   Am I lacking something or the AngleLimit were built not to reflect the change by program?


           PhysicsJointBehavior existingBehavior = behaviorEnumerator.Current as PhysicsJointBehavior;          

           if (existingBehavior != null)


               PhysicsJointMain pjm = existingBehavior.PhysicsJointMain;              

               pjm.AngleLowerLimit = 0;

               pjm.AngleUpperLimit = 100;

               pjm.AngleSpringEnabled = true;              



2. After reading the doc, I think the AngleJoint might meet my needs.  Is there a PhysicsJointBehavior of AngleJoint for Blend or I should do it by code?

3. Can I associate a physicsbody to a canvas programmatically and then make those physicsbodies joined with AngleJoint and finally control the TargetAngle of AngleJoint by code?

 Thanks for the help in advance.

Jun 8, 2010 at 2:11 PM

You're on the right track, there is just a problem where the PhysicsJointBehavior is only reading those values at initialization time.

If you just want to change the value at design time, set the AngleLimitLower and AngleLimitUpper values on the PhysicsJointBehavior.

If you _really_ want to do this at runtime, then you can access the Farseer Joint objects directly, by iterating through the Simulator.JointList:

foreach (Joint x in _physicsController.Simulator.JointList)

     if (x is AngleLimitJoint)
          AngleLimitJoint aj = x as AngleLimitJoint;
          // change the props as needed 





Jun 8, 2010 at 5:15 PM

Hi Andy, Thanks for the reply. 

I try to add PhysicsJointBehavior by code and it works fine but I need to identify a specific AngleLimitJoint for change the anglelimit programmatically.

Is there any way I can do except compare the name of BodyOne and BodyTwo of all JointList.

Jun 8, 2010 at 6:02 PM

I can't think of an easier way.

If you are worried about the performance of iterating the Joints collection, just make sure you only do this once - and then save the Joint to a member variable or somewhere to refer to later.

Nov 23, 2011 at 7:17 PM

Can you please give an example on how joint programmatically two newly created ellipses ?

Thank you.