I have this script for my 2d drone’s mouvement using AddForce wich work pretty well, but the problem is that if the player keep pushing the mouvement keys (in one direction), the drone will increase it speed until it becomes uncontrollable and goes way to fast. Could I prevent the forces from stacking up with a “setForce” (I know it doesn’t exist) or maybe assign a maximum speed to my rigidbody ?
void FixedUpdate ()
{
ControlDrone();
drone.AddRelativeForce(Vector2.up * rapidité);
drone.AddRelativeForce(Vector2.right * rapidité * direction);
}
void ControlDrone()
{
if (Input.GetAxisRaw("Vertical") > 0f)
{
rapidité = 15f;
}
if (Input.GetAxisRaw("Vertical") < 0f)
{
rapidité = 5f;
}
if (Input.GetAxisRaw("Vertical") == 0f)
{
rapidité = 9.81f;
}
if (Input.GetAxisRaw("Horizontal") > 0f)
{
direction = 1f;
}
if (Input.GetAxisRaw("Horizontal") < 0f)
{
direction = -1f;
}
if (Input.GetAxisRaw("Horizontal") == 0f)
{
direction = 0f;
}
}