Question by
raphasauer · Jan 11, 2017 at 08:29 PM ·
c#animationunity 52d
How to smooth this jumping script?
I'm using Add.Force to make my player jump. However it almost feels like the character is teleporting when it jumps. It seems like the Add.Force is adding all the force in one frame, causing this weird behavior. Is there a way to make it feel less like a teleport and more like an actual jump? I thought about making the force being more evenly distributed in the frames, but I've got no idea on how to do that. Any help is appreciated.
private void Update()
{
if (Input.GetKeyDown("up") || Input.GetButtonDown("Jump"))
rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Force);
}
Here is the inspector of the GameObject that I'm using as a player:
helpgame.png
(61.8 kB)
Comment
Answer by Intare · Jan 12, 2017 at 10:18 AM
Try doing it in the FixedUpdate instead the Update method.
The update method runs every frame, the FixedUpdate every physics update, so, when doing physics things, just use FixedUpdate.