- Home /
lookat() issue
I am making a sort of FPS and I need my camera to look at a specific object. I'm using the lookat() method, which does exactly what i want except it does it simply changes my camera rotation from my current to where i want it to look at instantly. Instead I would like for it to perform this rotation over time. Any suggestions?
Answer by syclamoth · Sep 21, 2011 at 02:55 PM
Instead of using lookat() directly, try using an intermediate step-
targetRotation = lookat(whatever);
actualRotation = Quaternion.Slerp(currentRotation, targetRotation, Time.deltaTime * someAmount);
This makes the actual rotation lag behind the target rotation a little, but it should smoothly follow the way you want it to!
Nice! Now the issue i have is that lookat() is a void function, therefore not returning the target rotation. How can I get the rotation ins$$anonymous$$d?
You should use Quaternion.LookRotation (assu$$anonymous$$g whatever is a Transform):
targetRotation = Quaternion.LookRotation(whatever.position);
Since LookRotation asks for a point, you must pass the target's transform.position to make it look at the target object.
That worked too and it made it look great :) thank you very much for the help!
Your answer
Follow this Question
Related Questions
Rotation Reset 0 Answers
Transform.LookAt and Back! 1 Answer
Look at an angle 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers