# How do I create “drag” when my character turns around?

I've been trying to give my character some drag when it turns in the opposite direction, but for some reason my acceleration variable only seems to apply itself when my horizontal velocity is 0. For example, if my character is standing still, and my horizontal acceleration is set to 0.5 seconds, it takes my character 0.5s to reach its maximum velocity. However, if I reach this velocity, and then begin to turn around, the transition is much faster. This doesn’t make sense to me because it should take less time to go from 0 to 10 than it does to go from 10 to -10.

It is very easy to see this difference in my game, as even if I change my acceleration to 3s, once I reach my maximum velocity I can turn around almost instantly. I'm using the smoothdamp function, and have tried a few other methods than the one in the code below, one of which distinguished between two distinct velocity smoothing variables. I felt that this created a better feeling of drag, but could result in jerky movement depending on input.

Should I be using smoothdamp for this kind of movement, or is there a more effective solution? Ideally I'd like to have this drag increase or decrease according to my current velocity.

private void FixedUpdate ()
{
HandleInput();
}

private void SetHorizontalForce(float x)
{
if (directionalInput.x != 0)
{
velocity.x = Mathf.SmoothDamp(velocity.x, x, ref velocityXSmoothing,
(State.IsCollidingBelow) ? Parameters.accelerationTimeGrounded : Parameters.accelerationTimeAirborne);
}

else if (directionalInput.x == 0) //Prevents the character from 'sliding' if suddenly moving left and right at low velocities
{
velocity.x = Mathf.SmoothDamp(velocity.x, 0, ref velocityXSmoothing, Parameters.stopTime);
}
}

private void HandleInput()
{
directionalInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

{
SetHorizontalForce(directionalInput.x * stats.movementSpeed);
}

• (1) What you call "drag" is actually inertia. Drag is something else (akin to atmospheric dampening - e.g. a parachute enables you to fall slowly, because it has a high drag coefficient). (2) my horizontal acceleration is set to 0.5 seconds, it takes my character 0.5s to reach its maximum velocity This inverts the meaning of acceleration. In physics, the higher your acceleration is, the less time you need to reach a given top speed. But in your code, setting the acceleration to a higher value makes the object accelerate slower, which is counterintuitive. – Flater May 29 '18 at 11:28
• Have you considered to use a rigidbody and cause movement by adding forces? It might give you a more physically plausible gameplay. – Philipp Oct 6 '18 at 13:03

Your SmoothDamp function can take a fifth maxSpeed parameter. See if giving it a proper limit works.
 if (directionalInput.x != 0)