enemy LookAt Player Slerp
What my code is doing is it is having the enemy match the players rotation..so whatever direction I look so does he. What I want is that he rotates to look at me -. I was simply using "transform.LookAt(Player);" but it was too fast so trying to figure out how to combine the LookAt(player) with the Slerp script below but can't seem to merge the two.
Transform Player;
Transform enemy;
public float speed;
NavMeshAgent agent;
void Start () {
enemy =GameObject.Find("NAZI_SOLDIER").transform;
Player=GameObject.FindGameObjectWithTag("Player").transform;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
//transform.LookAt(Player);
transform.rotation = Quaternion.Slerp (enemy.rotation, Player.rotation, Time.deltaTime * speed);
agent.enabled = false;
}
}
Answer by shadowpuppet · Jan 28, 2017 at 06:37 PM
after several attempts I snatched some code from a smoothLookAt java script camera code. The part that really threw me was the "var" thinking it was just a JS script term. anyway...here is the code to have an enemy look at the player smoothly instead of a snap to position as the LookAt (Player) did
var rotation = Quaternion.LookRotation(Player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
Your answer
Follow this Question
Related Questions
unwanted rotation in y axis 0 Answers
Substitute transform.rotation + slerp with transform.rotate and Vector3 0 Answers
How to Slerp / Lerp Rotation on a Single Axis? 0 Answers
3D First Person Game, 2D Enemy Face Player/Camera 1 Answer
Player is rotating towards mouse in too large of an arc 1 Answer