Can somebody please help me with my code - what do i need to add to make my camera turn SMOOTHLY towards the enemy?
So i have this code and everything is working just fine - as soon as the enemy is within a given vicinity my players camera is turned towards it. As of now the camera just "jumps" directly into the new "lookAt position"...what do i need to add to make my player's camera turn smoothly?
Heres my code (done in javascript):
var camLookAt : Transform;
var cameraUsed : Camera;
var Haunt : GameObject;
function SetCam()
{
if(PlayerSpawnTrigger.spawning == true)
{
if(GameObject.Find("Haunt") != null)
camLookAt.position = GameObject.Find("Haunt").transform.position;
}
}
function Update()
{
SetCam();
if (GazeChecker.ForceGaze == true)
{
cameraUsed.transform.LookAt (camLookAt);
}
}
Thx a lot guys ;)
Answer by L20GAMES · Apr 04, 2016 at 07:45 AM
I may be wrong here but I would think using something like:
var camLookAt : Transform
function Update(){
transform.LookAt(camLookAt * Time.deltaTime);
}
I could be wrong but it should be something along those lines.
I will try that right away when I get home. I'll let you know and post the result- thank you very much!
Answer by Namey5 · Apr 04, 2016 at 09:42 AM
Just posted a link cause I didn't have much time. If you want full code, just use this:
var target : GameObject;
var speed : float;
function Update ()
{
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (target.transform.position - transform.position), Time.deltaTime * speed);
}
Your answer
Follow this Question
Related Questions
How to make a camera follow a ball from behind? c# 3 Answers
Camera Script remove a part. 0 Answers
Show device camera preview (Android & iOS) 1 Answer
My model is shaking 0 Answers
problem ghosting camera with 2 objets 0 Answers