I’m trying to wrap my head around Drag works in Unity physics, and I’m getting nowhere.
Simply put, I’m making a space shoot 'em up and I want to use drag for simplified breaking thrusters to slow the ship down to a stop, when hands are off the controls. At the same time I want to be able to apply relative force to the ship in any given direction, with constant acceleration regardless of how high or low the drag is set.
I know there is a forcemode for acceleration, but I still need “mass” to be part of the equation, so I just want to be able to counter the drag without having to change the thruster force parameters in the inspect.
How could I do this?
This is what my maneuvering function looks like, that runs in FixedUpdate.
private void FireThrusters()
{
var targetSpeed = new Vector2(MaxSpeed * direction.x, MaxSpeed * direction.y);
if (direction.y > 0.0f && rb.velocity.z < targetSpeed.y)
rb.AddRelativeForce(Vector3.forward * Thrust);
else if (direction.y < 0.0 && rb.velocity.z > targetSpeed.y)
rb.AddRelativeForce(-Vector3.forward * Thrust);
if (direction.x > 0.0f && rb.velocity.x < targetSpeed.x)
rb.AddRelativeForce(Vector3.right * Thrust);
else if (direction.x < 0.0 && rb.velocity.x > targetSpeed.x)
rb.AddRelativeForce(-Vector3.right * Thrust);
CameraCorrectMovement();
}
I did experiment with creating actual breaking thrusters, and setting drag ot 0, but that resulted in an odd anomaly, where the ship would drift efter so slightly after any kind of collision, but still register as having a velocity of 0.