I feel like I'm having a colossal brain fart right now, but I can't figure this out.
void FixedUpdate()
{
moveHorizontal = Input.GetAxis("Horizontal");
moveVertical = Input.GetAxis("Vertical");
jump = Input.GetAxis("Jump");
movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
if (canJump)
{
rb.AddForce(0, jump * jumpHeight, 0);
}
}
Player movement works fine but jumping is buggy. If I apply the force to jump in FixedUpdate, it gets missed sometimes if the player is jumping a lot, and also, for some reason, if the player is moving diagonally(Like maybe GetAxis is being overloaded with three buttons being pressed?!).
But if I move it to Update, a. I'll have frame rate related issues in the build, right? And b. the jumping works perfect except every once in a while the player jumps much higher, which I believe is the result of the force being added twice. Maybe I'm interpreting it all wrong? I don't like using GetAxis or Unity's physics engine, there's too much going on under the hood.
↧