Search Unity

Smooth mouse rotation speed with fine control for aiming?

Discussion in 'Scripting' started by Scott2112, May 4, 2016.

  1. Scott2112

    Scott2112

    Joined:
    Feb 1, 2016
    Posts:
    12
    I have a turret that is controlled with mouse input. The problem is I can't get a balance between rotating fast enough and not losing fine control for aiming at the target. Below is the code. I've experimented with different Lerp speed times, calling from Update, FixedUpdate, LateUpdate etc... nothing has worked.




    rayCastFromMouse();

    Reference.LookAt(objectivePos);

    Quaternion relative = Quaternion.Inverse(bodyRotY.transform.rotation) * Reference.rotation;



    //rotation of the second axis
    Quaternion objectiveRot = Quaternion.Euler(Reference.rotation.eulerAngles[0] - 110, Reference.eulerAngles[1], 0);
    bodyRotZ.transform.rotation = Quaternion.Lerp(bodyRotZ.transform.rotation, objectiveRot, Time.deltaTime * lerpSpeed);


    //rotation of the firts axis
    objectiveRot = Quaternion.Euler(0, Reference.rotation.eulerAngles[1] - 90, 90); // -90,90
    bodyRotY.transform.rotation = Quaternion.Lerp(bodyRotY.transform.rotation, objectiveRot, Time.deltaTime * lerpSpeed);