Note that there are some explanatory texts on larger screens.

plurals
  1. POXNA, smoother jumping animations
    text
    copied!<p>I'm trying to make jumping functionality in my Movement test. My character jumps and comes back down, but it's very choppy and not smooth at all. What happens is he juts up to his max height, then comes down smoothly. </p> <p>I can spot the problem, the for loop doesn't want to play nicely with the code. However, I don't know how to circumvent this. Is there any way to keep the button press and have him jump up nicely?</p> <p>Code: </p> <pre><code>if (leftStick.Y &gt; 0.2f &amp;&amp; sprite.Position.Y == position.Y || isPressed(Keys.Up) == true &amp;&amp; sprite.Position.Y == position.Y) { if (wasLeft == true) { sprite.CurrentAnimation = "JumpLeft"; } else if (wasLeft == false) { sprite.CurrentAnimation = "JumpRight"; } //This for loop is my issue, it works but it's jumpy and not smooth. for (movement.PlayerHeight = 0; movement.PlayerHeight &lt; movement.PlayerMaxHeight; movement.PlayerJump()) { sprite.Position.Y -= movement.PlayerJump(); } } sprite.StartAnimation(); } else { leftStick = NoInput(leftStick); } private Vector2 NoInput(Vector2 leftstick) { if (sprite.Position.Y &lt; position.Y) //(movement.PlayerSpeed &gt; 0) { sprite.Position.Y += movement.PlayerHeight; movement.PlayerHeight -= movement.Player_Gravity; //sprite.Position.Y += movement.PlayerSpeed; //movement.PlayerSpeed -= movement.Player_Decel; } else { sprite.Position.Y = position.Y; } } </code></pre> <p>Movement class:</p> <pre><code>public float PlayerMaxHeight = 15f; public float PlayerHeight = 0; public float Player_Gravity = 0.01f; private const float Player_Jump = 0.35f; public float PlayerJump() { PlayerHeight += Player_Jump + Player_Gravity; if (PlayerHeight &gt; PlayerMaxHeight) { PlayerHeight = PlayerMaxHeight; } return PlayerHeight; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload