i'm trying to create a simple cutscene, how can i tell to the object to rotate until it looks at something, or to rotate only when it's angle is < of something
it's my script for now
transform.Rotate(Vector3.up * Time.deltaTime * 18);
i'm trying to create a simple cutscene, how can i tell to the object to rotate until it looks at something, or to rotate only when it's angle is < of something
it's my script for now
transform.Rotate(Vector3.up * Time.deltaTime * 18);
The easiest way is `transform.LookAt()`. Then your character will face the object. You could also use `Quaternion.LookRotation()` then check to see when that angle matches the player's angle.
http://unity3d.com/support/documentation/ScriptReference/Quaternion.LookRotation.html
You can use Quaternion.LookRotation to find the rotation required to make your object look in a specific direction or at a specific point.
You can then use Quaternion.RotateTowards to make your object gradually rotate towards that rotation.
I know the post is kind of old, but it helped me, and this is how I solved this question:
#pragma strict
var target : Transform;
var speed: float;
function Update () {
// find Rotation towards target
var relativePos = target.position - transform.position;
var rotation = Quaternion.LookRotation(relativePos);
// Rotate our transform a step closer to the target's.
var step = speed * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, step);
}