2D player slower on ground than in air
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 http://answers.unity3d.com/questions/1258619/jumping-is-slightly-faster-than-running-due-to-fri.html 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)
Ground settings (ground material also has 0.5 friction)
Answer by serg06 · Apr 17, 2017 at 06:31 PM
Update: After replacing my addForce with velocity+=, it's still bumpy between 8.0 and 8.1, but it feels much more natural.