I'm trying to move a 2D object around the mouse position, However, i want to constrain the object from rotating unnaturally around itself, i want it to basically rotate around a radius, similar to how a boat moves. I've provided the boat example below of what i am trying to achieve, the game is called battleboats.io and their rotation around the mouse will not skid, it looks natural like propellers pushing from behind.
Here's my code for achieving this in unity:
public Camera camera;
public Rigidbody2D rigidbody;
private float rotationSpeed = 200f;
private float acceleration = 4.4f;
Vector3 GetMousePosition(Camera c)
{
return c.ScreenToWorldPoint(Input.mousePosition);
}
void Update()
{
Vector3 direction = GetMousePosition(camera) - transform.position;
direction.Normalize();
float rotationAngle = Vector3.Cross(direction, transform.up).z;
//rotation
rigidbody.angularVelocity = -rotationAngle * rotationSpeed;
//forward momentum
rigidbody.velocity = transform.up * acceleration;
}
Any help is appreciated.
What i currently have and the result of my code is illustrated in the below gif.