- Home /
LookAt() on Animated GameObject
I'm having problems getting an enemy to look at my player. The enemy has an animation sequence on it. I'm using the LookAt() function in the LateUpdate() as according to the Unity documentation it occurs after the Animation does. In addition, the rotations on the enemy animation don't have any keyframes or nor curves.
Does anyone know how to do this?
Just to clarify, I'm not looking for the enemy to smoothly look towards the target, just always to be facing it. The animation sequence applies to the transform.position only, so shouldn't the LookAt() being in LateUpdate() be what I want?
For future reference, I believe I've figured this out. It was a bit of a hack though.
At the end of Update(), I performed the LookAt() function and then immediately assigned the transform.rotation values to a variable. Then in the LateUpdate() I assign the transform.rotation to be the variable's values. Not exactly "clean" but it's working. I'm thinking that perhaps the LookAt() runs a coroutine in Javascript and that perhaps it wasn't being completed until after the frame was rendered to screen.
Answer by darthbator · Jun 01, 2013 at 12:23 AM
That's because it's not an animation. If you're using look at you're just setting the character rotation to align it's forward towards the thing you're passing in. You will likely want to look into the Quaternion class. Specifically the setLookRotation and RotateTowards/SLERP methods.
I realize that it's not an animation. It simply clamps to have the rotation face towards the target from my understanding. That's what I need (I don't want a lerp or slerp), but it seems to getting ignored even though it's in the LateUpdate. Or are you saying that the SetLookRotation() clamps to look at the target as well?
Your answer
Follow this Question
Related Questions
How to make animated animal's head smoothly look at player instead of instantly snapping? 1 Answer
NPC look at camera help! 1 Answer
LookAt() animation 2 Answers
How to make player look at opponents? 1 Answer
Rabbit model facing target. 1 Answer