This leads to a problem where jumping at a box collider and landing on the top corner gets you stuck. Can’t walk toward the platform, and won’t fall; you only fall if moving away.
I’m using some semi-complex movement code:
public float maxSpeed = 10f;
void HandleInput() {
// Walking left/right
float move = Input.GetAxis ("Horizontal");
float forceMultiplier = 0.1f;
if (Mathf.Abs (rigidbody2D.velocity.x) < maxSpeed) {
forceMultiplier = 5 * (1 - Mathf.Abs (rigidbody2D.velocity.x) / maxSpeed);
if (!onGround)
forceMultiplier *= 0.2f;
}
rigidbody2D.AddForce (new Vector2 (move * maxSpeed * forceMultiplier, 0));
}
This allows for reduced air control, rapid acceleration, and force-based movement.