Search Unity

Smooth look at on Y axis only?

Discussion in 'Scripting' started by Warrior1424, Apr 26, 2011.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Anyway to make a smooth lookat, but not change the Z and X axis, only the Y?
     
  2. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
  3. JohnnyCheese

    JohnnyCheese

    Joined:
    May 10, 2011
    Posts:
    8
    Looking for my self here, So far my lookAt scripts make the object face towards the ground upon initialiation which kinda looks funny
     
  4. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Code (csharp):
    1.  
    2. var target : Transform;
    3. var rotSpeed : float;
    4.  
    5. function Update(){
    6.     var targetPos = target.position;
    7.     targetPos.y = transform.position.y; //set targetPos y equal to mine, so I only look at my own plane
    8.     var targetDir = Quaternion.LookRotation(targetPos - transform.position);
    9.     transform.rotation = Quaternion.Slerp(transform.rotation, targetDir, rotSpeed*Time.deltaTime);
    10. }
    11.