Basically I have a character with a collider and rigidbody and a wall with a collider in a 2D setting.
The character’s rigidbody has no Drag or Gravity (all 0).
The character moves using this code during Update():
Vector2 Velocity = new Vector2(0,0);
if (Input.GetKey(KeyCode.W))
{
Velocity.y = 5;
}
else if (Input.GetKey(KeyCode.S))
{
Velocity.y = -5;
}
if (Input.GetKey(KeyCode.A))
{
Velocity.x = -5;
}
else if (Input.GetKey(KeyCode.D))
{
Velocity.x = 5;
}
GetComponent<Rigidbody2D>().velocity = Velocity;
If I move down and right (S & D keys) it moves fine until I hit a wall below me, at which point the movement on the Y axis stops completely (as it should, I hit a wall), but the movement along the X axis slows down as well. Why does this happen? I don’t want the X-axis velocity to slow down just because they are also trying to run along a Y axis that is blocked by a wall.