Answers for "unity how to make a gameobject slowly look at a position"

C#
4

unity how to make a gameobject slowly look at a position

Quaternion lookAtSlowly(Transform t , Vector3 target , float speed){
  
  //(t) is the gameobject transform
  //(target) is the location that (t) is going to look at
  //speed is the quickness of the rotation
  
   Vector3 relativePos = target - t.position;
   Quaternion toRotation = Quaternion.LookRotation(relativePos);
   return Quaternion.Lerp(t.rotation, toRotation, speed * Time.deltaTime);
}

void update()
{
  transform.rotation = lookAtSlowly(transform , new Vector3(0,0,0) , 1);
}
Posted by: Guest on June-24-2020

Code answers related to "unity how to make a gameobject slowly look at a position"

C# Answers by Framework

Browse Popular Code Answers by Language