This project has moved and is read-only. For the latest updates, please go here.

Weldjoint problem

Topics: User Forum
Jan 24, 2011 at 9:42 PM


I am new with Farseer.  I use the  farseerphysics-83195 xna HELLO WORLD example and changed it into a pinball game. At this moment I have more then 700 lines of working code, but I cannot make a weldJoint work.

I Use a circle as pivot for my flippers but can not join them. I get an assertion failed message.

here is the code for the flipper, pivot, joint and the debug info:

            //Load texture that will represent the rightflipper body
            uint[] flipperrightdata = new uint[flipperrightTexture.Width * flipperrightTexture.Height];
            Vertices rightflipperverts = PolygonTools.CreatePolygon(flipperrightdata, flipperrightTexture.Width, flipperrightTexture.Height, true);
            Vector2 flipperrightscale = new Vector2(0.0155f, 0.014f);
            rightflipperverts.Scale(ref flipperrightscale);
            _list = BayazitDecomposer.ConvexPartition(rightflipperverts);
            rightflipper = FixtureFactory.CreateCompoundPolygon(_world, _list, 1);
            rightflipper[0].Body.BodyType = BodyType.Static;
            rightflipper[0].Body.Position  = new Vector2(300 / _meterInPx, 640 / _meterInPx);
            rightflipper[0].Restitution = 0.8f;

            // Create the rightpivot fixture
            Vector2 rightpivotFixturePosition =new Vector2 (rightflipper[0].Body.Position .X+(80/_meterInPx), rightflipper[0].Body.Position.Y+ (25/_meterInPx));
            rightpivotFixture = FixtureFactory.CreateCircle(_world, 30f / (2f * _meterInPx), 1f, rightpivotFixturePosition);
            rightpivotFixture.Body.BodyType = BodyType.Static;
            rightpivotFixture.Restitution = 1f;
            rightpivotFixture.Friction = 0.5f;
            position = rightpivotFixturePosition * _meterInPx;

            //join rightflipper and pivot
            Vector2 rightAnchor = new Vector2(rightflipper[0].Body.Position.X + (80 / _meterInPx), rightflipper[0].Body.Position.Y + (25/_meterInPx));
            rightflipperjoint = JointFactory.CreateWeldJoint(_world, rightpivotFixture.Body, rightflipper[0].Body, rightAnchor);

Debug info:

 public void AddJoint(Joint joint)
            //You are adding the same joint twice?

            if (!_jointAddList.Contains(joint))

+        this    {FarseerPhysics.Dynamics.World}    FarseerPhysics.Dynamics.World
-        joint    {FarseerPhysics.Dynamics.Joints.WeldJoint}    FarseerPhysics.Dynamics.Joints.Joint {FarseerPhysics.Dynamics.Joints.WeldJoint}
-        [FarseerPhysics.Dynamics.Joints.WeldJoint]    {FarseerPhysics.Dynamics.Joints.WeldJoint}    FarseerPhysics.Dynamics.Joints.WeldJoint
+        base    {FarseerPhysics.Dynamics.Joints.WeldJoint}    FarseerPhysics.Dynamics.Joints.Joint {FarseerPhysics.Dynamics.Joints.WeldJoint}
+        _impulse    {X:0 Y:0 Z:0}    Microsoft.Xna.Framework.Vector3
+        _mass    {FarseerPhysics.Common.Mat33}    FarseerPhysics.Common.Mat33
+        LocalAnchorA    {X:0 Y:0}    Microsoft.Xna.Framework.Vector2
+        LocalAnchorB    {X:1,25 Y:0,390625}    Microsoft.Xna.Framework.Vector2
        ReferenceAngle    0.0    float
+        WorldAnchorA    {X:5,9375 Y:10,39063}    Microsoft.Xna.Framework.Vector2
+        WorldAnchorB    {X:5,9375 Y:10,39063}    Microsoft.Xna.Framework.Vector2
        Active    true    bool
+        BodyA    {FarseerPhysics.Dynamics.Body}    FarseerPhysics.Dynamics.Body
+        BodyB    {FarseerPhysics.Dynamics.Body}    FarseerPhysics.Dynamics.Body
        Breakpoint    3.40282347E+38    float
        Broke    null    System.Action<FarseerPhysics.Dynamics.Joints.Joint,float>
        CollideConnected    false    bool
+        EdgeA    {FarseerPhysics.Dynamics.Joints.JointEdge}    FarseerPhysics.Dynamics.Joints.JointEdge
+        EdgeB    {FarseerPhysics.Dynamics.Joints.JointEdge}    FarseerPhysics.Dynamics.Joints.JointEdge
        Enabled    true    bool
        InvIA    0.0    float
        InvIB    0.0    float
        InvMassA    0.0    float
        InvMassB    0.0    float
        IslandFlag    false    bool
        JointType    Weld    FarseerPhysics.Dynamics.Joints.JointType
+        LocalCenterA    {X:0 Y:0}    Microsoft.Xna.Framework.Vector2
+        LocalCenterB    {X:0 Y:0}    Microsoft.Xna.Framework.Vector2
        UserData    null    object
-        WorldAnchorA    {X:5,9375 Y:10,39063}    Microsoft.Xna.Framework.Vector2
        X    5.9375    float
        Y    10.390625    float
+        Static members       
-        WorldAnchorB    {X:5,9375 Y:10,39063}    Microsoft.Xna.Framework.Vector2
        X    5.9375    float
        Y    10.390625    float
+        Static members   

It must be something simple I do  wrong, but cannot figure it out.

Tanks in advance,


Jan 24, 2011 at 10:34 PM
The method JointFactory.CreateWeldJoint() when passed World automatically adds the joint to the World.