How can I prevent my gameobject from rotating all the time when trying to move it

Viewed 56

So I have a gameobject (my player) which moves via a joystick. Without the rotating code below my player moves well and smooth, but after I put the rotating code below the gameobject rotates all the time (360 degrees) when I try to move it.

My aim is to rotate the player around a specific angle when the player turns.

void Update()
{
    // move
    _rigidbody.MovePosition(transform.position + (transform.forward * leftController.GetTouchPosition.y * Time.deltaTime * speedMovements) +
        (transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMovements) );

    //rotate 
    double rad = Mathf.Atan2(leftController.GetTouchPosition.y, leftController.GetTouchPosition.x); // In radians
    double deg = rad * (180 / System.Math.PI);
    transform.RotateAround(transform.position, Vector3.up * Time.deltaTime, (float) deg);
}
1 Answers
Related