Во ударением прыжка, скорость Y полностью переопределен кривой мощности. Во время приличной силы тяжести принимает . Скорость скачка регулируется полем jumpTime
, которое измеряет время в акценте текущего скачка.
Во-первых вам понадобятся некоторые простые глобальные переменные,
public bool isJumping; //Is the player in a jump?
private bool wasJumping; //Did the player just exit a jump?
private float jumpTime; //Time the player has been in a jump (Useful for adding a power curve or to max out on jump height)
MaxJumpTime = .8f; //If you want to max out a jump, otherwise remove the relevant parts of the code
JumpLaunchVelocity = -3000.0f; //How much velocity to "jump" with, this may depend on your speed of your player, so it will need some ajustment
Вот функция, которая делает большую часть работы:
private float DoJump(float velocityY, GameTime gameTime)
{
// If the player wants to jump
if (isJumping)
{
// Begin or continue a jump
if ((!wasJumping && IsOnGround) || jumpTime > 0.0f)
{
//Do things like animate, or play a sound here
jumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
}
// If we are in the ascent of the jump
if (0.0f < jumpTime && jumpTime <= MaxJumpTime)
{
// Fully override the vertical velocity with a power curve that gives players more control over the top of the jump (If you dont want this you can remove the Math.Pow)
velocityY = JumpLaunchVelocity * (1.0f - (float)Math.Pow(jumpTime/MaxJumpTime, JumpControlPower));
}
else
jumpTime = 0.0f; // Reached the apex of the jump
}
else
{
// Continues not jumping or cancels a jump in progress
jumpTime = 0.0f;
}
wasJumping = isJumping;
return velocityY;
}
В вашем обновлении при вычислении позиции и прочее:
velocity.Y = DoJump(velocity.Y, gameTime);
Посмотрите на Platformer Starter Kit, если у вас возникнут проблемы s!
Проанализировали ли вы работу с кнопками вниз и активировали события как отдельные события, а затем задали интервал между ними? – ChrisF