This question was
closed Dec 05, 2020 at 09:49 PM by
kris007_iron for the following reason:
The question is answered, right answer was accepted
How to rotate the enemy in 2D top down
I use that script to rotate enemy but he stop at 90 and -90 deegres. Any solution Start rotation0/-90/90
public class LookAtSth : MonoBehaviour
{
public Transform target;
public float rotationSpeed;
private Quaternion lookRotation;
private Vector3 direction;
public void Start()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
direction = (target.position - transform.position).normalized;
lookRotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, 90);
}
}
Comment
Follow this Question
Related Questions
How to make all enemies attack after spawning? Not only 1. 1 Answer
How To Destroy/Deactivate one enemy without affecting other enemies of the same type? 0 Answers
How to make a NavMeshAgent follow player in FixedUpdate to avoid jitters? 0 Answers
Trying to add a tracker to enemy AI either prefab or with reference 0 Answers