How to fix the rotation bug?
Hi,
I made this script and I don't know why my enemy is rotating on hiself... I'm a beginner and the game that I am doing is a 2D RPG
The goal of the script is to do a line between the enemy and the player. Like that, the monster(slime) will follow this line to the player to attack him(eventually)...
public Transform target;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
////////////////////////////////////////
void Awake()
{
myTransform = transform;
}
void Start()
{
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
}
void Update()
{
Debug.DrawLine(target.transform.position, myTransform.position, Color.yellow);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Sorry for my english...
Thank you :)
Comment
Your answer
Follow this Question
Related Questions
Help with 2D Enemy Animations 0 Answers
How to keep an array of targets in detection radius? 0 Answers
Enemy raycast detects player only at constant distance 0 Answers
How to differ between LoadLevel and starting the scene for the first time 2 Answers
2D Sprite is floating when I move him (Rigidbody2D) 0 Answers