Hi guys. I’m making a 2D platformer and my player is slower on the ground than in the air for some reason.
When I’m in the air, my speed steadily approaches my maxSpeed, 10.0, however on the ground it fluctuates between 6.8 and 7.0. This is how I add speed (maxSpeed and speed are constants):
float xaxis = Input.GetAxisRaw ("Horizontal");
rb.AddForce (new Vector2 (xaxis, 0) * (Mathf.Max (maxSpeed - Mathf.Abs (rb.velocity.x), 0)) * speed);
I tried following Jumping is slightly faster than running due to friction - Questions & Answers - Unity Discussions and disabling player’s friction when not holding movement key, but it didn’t change anything:
if (xaxis == 0) {
bc.sharedMaterial.friction = defaultFriction;
rb.sharedMaterial.friction = defaultFriction;
} else {
bc.sharedMaterial.friction = 0;
rb.sharedMaterial.friction = 0;
}
Player settings (player material just has 0.5 friction)
!(http://i.imgur.com/VsStr0e.png)
Ground settings (ground material also has 0.5 friction)