attaching an object to a chain

Topics: User Forum
Mar 1, 2010 at 8:17 PM
Edited Mar 1, 2010 at 8:20 PM

Hey,

I'm playing around with the CreateChain function on the ComplexFactory and the chain I've created is swinging nicely. Now i would like to attach another object to the end of the chain (a lamp to be specific) but it keeps falling down :( Hope somebody can point me into the right direction and show me what I'm doing wrong.

This is the code I'm using:

 

_chain = ComplexFactory.Instance
.CreateChain(physicsSimulator,
new Vector2(1600, 0),
new Vector2(1700, 800), 120, 20, 0.5f, true, false,
LinkType.RevoluteJoint);

_lampBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, (float)Lamp.Width, (float)Lamp.Height, 1);
_lampBody.Position = new Vector2(1500, 800);
_lampBody.IsStatic = false;// true; JointFactory.Instance.CreateAngleJoint(physicsSimulator, _lampBody, _chain.Bodies.Last());


I'm using the body positions in my renderloop to transform the objects to the screen location.

Thanks a lot for your time and the farseer library!

cheers,

Ernst

 

Mar 1, 2010 at 8:36 PM

Ah, succes :)

 

            var context = PhysicsControllerMain.GetPhysicsController(LayoutRoot);
            var physicsSimulator = context.Simulator;

            _chain = ComplexFactory.Instance
                .CreateChain(physicsSimulator,
                             new Vector2(1600, -75),
                             new Vector2(1700, 700), 120, 20, 0.5f, true, false,
                             LinkType.RevoluteJoint);
 
            _lampBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, (float)Lamp.Width, (float)Lamp.Height, 1);
            _lampBody.Position = _chain.Bodies.Last().Position;

            var joint = JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _chain.Bodies.Last(), _lampBody, _chain.Bodies.Last().Position);

            _chain.Add(joint);
            _chain.Add(_lampBody);

Adding the body & joint to the chain seems to do the tick, thanks for the engine guys!

 

cheers,

Ernst