Search Unity

Rotate Object depending on mouse movement

Discussion in 'Scripting' started by BillyThePro, Feb 20, 2020.

  1. BillyThePro

    BillyThePro

    Joined:
    Feb 20, 2020
    Posts:
    1
    Hello, I want to add a script to my Spaceship which allows it to rotate about 45degrees both sides, depending on the distance and the position of the mouse from it .The position of the spaceship after some time will become the same with the mouse(different script) at wich point the angle should be 0degrees.The problems that I have with my script is the jittering it creates when the mouse movements are too slow and how fast the angle becomes 0degrees(before the spaceship reaches the mouse).

    public float tiltangle = 45f;
    public float smooth = 0.1f;
    void LateUpdate()
    {
    if (Input.GetMouseButton(0))
    {


    float move = Input.GetAxis("Mouse X");
    transform.rotation = Quaternion.Euler(Vector3.forward * tiltangle * -move * smooth);
    }
    }


    I tried more complicated things but to no avail.