My game is a top down ship game and I really don't like how movement is turning out. I am using Rigidbody2D.AddRelativeForce , which seems to be my best option for moving based on direction the ship is facing, however I have an annoying consequence of drifting once speed picks up. I want the ship to constantly move forward, which I think is the main problem, because the force never stops being applied. If there is a better option, or a way to tweak AddRelativeForce, I would greatly appreciate some input. Here is a video of it happening: https://imgur.com/a/wisycZL And here is the code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { Rigidbody2D rb; [SerializeField] public float accelerationPower = 1f; [SerializeField] public float steeringPower = 1f; float steeringAmount, direction; void Start() { rb = GetComponent<Rigidbody2D>(); windDirection = compass.GetComponent<Wind>(); } // Update is called once per frame void FixedUpdate() { steeringAmount = Input.GetAxis("Horizontal"); direction = Mathf.Sign(Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up))); rb.rotation += steeringAmount * steeringPower * rb.velocity.magnitude * direction; rb.AddRelativeForce(-Vector2.up * accelerationPower * Time.deltaTime); rb.AddRelativeForce(-Vector2.right * rb.velocity.magnitude * steeringAmount / 2); } }
This might be a roundabout way but simple way to fix it. When you want it to slow down or stop drifting so much, increase the mass or friction temporarily. That will slow it down. You could have some function where if there is no user input for X seconds, it calls another function that increases the mass or friction. Try the variables on the Rigidbody2D component. In theory, this should slow it down and stop so much drifting, but i actually havent tried anything like this.