#pragma strict // Note: Since the video was made we changed "player" to "target" to make the // script more universal. We also added a new function that will set a new target. // Target object, or object which the character will look at. var targetObject : GameObject; // Speed at which the turn will occur. 1 = 1 unit / second. var turnSpeed : float = 4.0; function Start(){ // If targetObject is not already assigned // Assign "PlayerController" object in scene to variable. if (!targetObject) targetObject = GameObject.Find("PlayerController"); } function Update(){ // Creates a Vector with the X/Z of the target, but the Y of the source // Otherwise, when the playerObject gets close to the characer doing the looking, // it will lean back or forward in order to Look At the player. var targetPositionFixed = Vector3(targetObject.transform.position.x, transform.position.y, targetObject.transform.position.z); // Get rotation between forward of two objects var targetRotation = Quaternion.LookRotation(targetPositionFixed - transform.position); // Turn towards playerObject over time. transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnSpeed); } // Call this function in any way you'd like to set a new targetObject. One method is to use // SendMessage() as so: SendMessage ("SetNewTarget", newTargetObject); // The script that calls SendMessage() must be on the same object as this script. function SetNewTarget(newTarget : GameObject){ targetObject = newTarget; } ---------------------------------------------------------- YOU ARE FREE TO USE THESE SCRIPTS IN YOUR PROJECT IN ANY WAY YOU WOULD LIKE! IF YOU HAVE PURCHASED OUR MODELS TO USE IN YOUR PROJECTS, WE THANK YOU VERY MUCH FOR YOUR SUPPORT! WITHOUT IT, WE COULDN'T KEEP MAKING MORE KILLER ASSETS FOR YOUR GAMES. ----------------------------------------------------------