0

I've tried following the example on XNA Development website but when the character jumps, they cant be controlled/cant stop the jump movement until its completed.

How do I get around that? Here is my jump code

private void Jump()
    {
        if (mCurrentState != FoxState.Jumping)
        {

            mCurrentState = FoxState.Jumping;
            mStartingPosition = Position;
            Direction.Y = Fox_vSpeed;
            Speed = new Vector2(Fox_Speed, Fox_Speed);
        }
    }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • I can't tell by the code you have provided, but my guess would be that you are not setting the mCurrentState once the Jump has 'finished'. Or you are missing the logic to work out if the jump is finished. Some where in your code will be using the 'Speed' property to set the updated position of the character. You'll want to add logic to modify Speed's Y component while the character is jumping. – Darren Reid Oct 04 '12 at 05:13
  • You should _add the code_ you're using to move sideways. My guess is that you can't move while your character is jumping. – Msonic Oct 04 '12 at 12:31
  • What is `Fox_Speed`? Where is the horizontal velocity of your character established? – Justin Skiles Oct 04 '12 at 13:50

1 Answers1

0

Gravity is simply a force that affects the acceleration of an object. Acceleration changes the velocity of an object so you can do just that: Speed -= Vector2.UnitY * -2; You can then check collision with an object on the ground and once such collision happens you can zero the Y component of Speed (and possibly incur damage on the poor fox if the Y component is too high in magnitude (absolute value)).

Something like:

Update(GameTime gt)
{
    if(mCurrentState == FoxState.Jumping)
    {
        Speed -= Vector2.UnitY * -2;
        Position += Speed;
        if(Position.Y > GroundLevel)
        {
            Position.Y = 0;
            mCurrentState = FoxState.Walking;
        }

    }
}

Modify your question with details if you need more information.

Lzh
  • 3,585
  • 1
  • 22
  • 36