Search Unity

Camera easing

Discussion in 'Scripting' started by unitynoob24, Mar 30, 2015.

  1. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Hello guys!

    I am working on a First Person project where the player has limited mobility, when they press A or D their view changes 90 degrees either to the left or right.

    I do that with this simple place holder code:

    transform.rotation.y = -1;

    and I use positive 1 for the other side.

    I am in the process of adding some kind of easing to this, because right now, the player will be looking ahead, then when they press to look to the left or right it just clips to the left or right. I want a nice smooth ease.

    So I have implemented this method and I can't figure out how to plug in what I need it to do to look left and right. I have it working though, the camera spins nice and smooth but on what looks to be the wrong axis and in the wrong direction.

    This is what I attempted for easing.

    Method:

    function RotateObject(startRot: Quaternion, endRot : Quaternion, rotateTime : float){

    var i = 0.0;
    var rate = 1.0/rotateTime;

    while(i < 1.0)
    {
    i += Time.deltaTime * rate;
    transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0.0, 1.0, i));
    yield;
    }

    }

    Usage:

    //transform.rotation.y = -1;

    RotateObject(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles + Vector3.forward * 90), 2.0);

    Any help would be greatly appreciated!

    Thanks guys!
     
  2. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Solved!

    I feel dumb.. I changed in the usage Vector3.forward to Vector3.up and it worked like a charm!