LookAt() not working?
Basically I want my player to look at something for a certain amount of seconds, and using LookAt vaguely works. However, it will only work when the player is already roughly looking at the gameobject, then it will lock on to the target. But lets say I decide to walk facing backwards, or look up, or look down... the players view does not turn to face the target whatsoever, rather just locks on to some imaginary object. Can anybody help me out here?
SCRIPT (C#):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAt : MonoBehaviour
{
public Transform monster;
void OnTriggerEnter (Collider other)
{
if (other.CompareTag("JumpScareTrigger"))
{
transform.LookAt (monster.transform);
}
}
}
Answer by alankemp · May 16, 2017 at 07:52 PM
Do you have another script that controls the player camera as they move around?
In this script you are setting the transform lookat once, on one frame. Your normal camera controller script is then running and pointing the camera in another direction.
The solution to this is to add the "look at for a certain amount of seconds" functionality to the other camera script.
Answer by Kzapas · May 26, 2020 at 09:43 PM
Like alankemp said. You should place your lookat in the update function.