Farseer/XNA jumping troubleshooting

Topics: Developer Forum
Aug 13, 2012 at 5:29 PM

Okay, so I've been troubleshooting making a 2D sidescroller in the vain of Super Mario Brothers, and right now I've got a rough directional code that applies torques to the body from Farseer, but I can't seem to figure out how to allow the player to augment his jump while he's in mid-air. Right now, this code allows for him to jump up in a straight line, but that's all. I am brand new to XNA and Farseer, so any recommendations would be greatly appreciated!

Thanks so much,



if (keyboardState.IsKeyDown(Keys.Left))
                direction = "left";
            else if (keyboardState.IsKeyDown(Keys.Right))
                direction = "right";
            else if (keyboardState.IsKeyDown(Keys.Q))
            if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
                bleak_circle.ApplyLinearImpulse(new Vector2(0, -10000f));
                if (keyboardState.IsKeyDown(Keys.Left))
                    bleak_circle.Position = new Vector2 (bleak_circle.Position.X - bleak_circle.LinearVelocity.X,0);
                direction = "up";

Aug 13, 2012 at 5:31 PM

The "Q" command is totally arbitrary and was only used to keep the circle body from moving infinitely, also the code for the body that is being used is here


        float recWidth = 70;
        float recHeight = 80;
        float circleRadius = 35;

        //bleak_rect = BodyFactory.CreateRectangle(world, 1.75f, 1.75f, 1.0f, new Vector2(2.0f, 0.0f));
        bleak_rect = BodyFactory.CreateRectangle(world, recWidth / MeterInPixels, recHeight / MeterInPixels, 0.1f, new Vector2(2.0f, 10.4f));
        bleak_rect.BodyType = BodyType.Dynamic;
        bleak_rect.Restitution = 0f;
        bleak_rect.Friction = 0.5f;
        bleak_rect.FixedRotation = true;

        bleak_circle = BodyFactory.CreateCircle(world, circleRadius / MeterInPixels, 1f, new Vector2(2.0f, 11.4f));
        bleak_circle.BodyType = BodyType.Dynamic;
        bleak_circle.Restitution = 0f;
        bleak_circle.Friction = 0.5f;
        bleak_circle.Inertia = 0f;

        RevoluteJoint joint = JointFactory.CreateRevoluteJoint(world, bleak_rect, bleak_circle, new Vector2(0.0f, 0.0f));
        joint.LimitEnabled = false;
        joint.MotorSpeed = 3.0f;
        joint.MotorEnabled = false;
        joint.MaxMotorTorque = 3;

Aug 27, 2012 at 11:47 PM

Your -10000f argument to ApplyImpulse seems really high. Are you sure you are using meters instead of pixels? Perhaps you should try and use the XNA Samples as a testbed for your game concept - it shows you how to convert between meters and pixels. If you fix that, perhaps the physics would help you instead of working against you.

As for your questions, I remember Mario being able to move mid air, if that is what you want, you simply use ApplyForce(10,0) while the movement keys are pressed. Remember to clamp his velocity or he will accelerate very quickly to a very high velocity.