An issue with odd jumping I had

Instead of simply assigning the velocity a new value in the jump method/function I was using +=

Bad code:
func jump(force):
velocity.y += -force

Correct code:
func jump(force):
velocity.y = -force

C# equivalent
Bad Code:
public void Jump(int force)
{
Velocity += new Vector2(Velocity.X, -force);
}

Good Code:
public void Jump(int force)
{
Velocity = new Vector2(Velocity.X, -force);
}

I figured I would share just in case anyone else made the mistake.

1 Like

Privacy & Terms