Pinning a camera body to the player

Topics: Developer Forum, User Forum
Sep 17, 2009 at 9:45 PM

this way i can have a camera that receives physics. my current code consists of the following:

 

camera = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, player1_torso_Texture.Width, player1_torso_Texture.Height, .0001f);
            camera.IgnoreGravity = true;
            camera.Position = player1_torso.Position;
            camera_joint = JointFactory.Instance.CreateSliderJoint(physicsSimulator, camera, camera.Position, player1_torso, player1_torso.Position, 0, 4f);

camera = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, player1_torso_Texture.Width, player1_torso_Texture.Height, .0001f);

camera.IgnoreGravity = true;

camera.Position = player1_torso.Position;

camera_joint = JointFactory.Instance.CreateSliderJoint(physicsSimulator, camera, camera.Position, player1_torso, player1_torso.Position, 0, 4f);

 

It works all good, but there doesn't seem to be a maximum distance they lock apart at. If i slam my player down on a clip brush really hard, my camera flies downward, instead of meeting player1_torso.Position "4" units away (described in the last argument of the last line of code). 

 

Also, i am assembling my player's body this way sorta. I tack the player's arm onto the body, but it still seems to fly off the player under extreme conditions.

Thanks

-keres