Answer the question
In order to leave comments, you need to log in
Why are they inside the dragon?
Hello! I started making bots for the game, but when they follow the player, they do not stand next to him, but climb inside him. How to fix? Script:
public Transform player;
public int dist;
public Transform enemy;
public float RotateSpeed;
public float SpeedMove;
public GameObject EnAnimObj;
private bool trig = false;
void Update()
{
if (trig == false)
{
Vector3 rotation = player.position-enemy.position;
enemy.rotation = Quaternion.Slerp(enemy.rotation, Quaternion.LookRotation(rotation), RotateSpeed * Time.deltaTime);
enemy.transform.position += enemy.forward * SpeedMove * Time.deltaTime;
enemy.transform.localPosition = new Vector3(transform.position.x, 0f, transform.position.z);
enemy.transform.localRotation = new Quaternion(0f, transform.rotation.y ,0f, transform.rotation.w);
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
GetComponent<Animator> ().SetTrigger ("Trigger");
trig = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
GetComponent<Animator>().SetTrigger("Trigger");
trig = false;
}
}
}
Answer the question
In order to leave comments, you need to log in
You need to add a minimum distance check.
void Update()
{
if (trig == false)
{
Vector3 rotation = player.position-enemy.position;
enemy.rotation = Quaternion.Slerp(enemy.rotation, Quaternion.LookRotation(rotation), RotateSpeed * Time.deltaTime);
if(rotation.sqrMagnitude > 1)
enemy.transform.position += enemy.forward * SpeedMove * Time.deltaTime;
enemy.transform.localPosition = new Vector3(transform.position.x, 0f, transform.position.z);
enemy.transform.localRotation = new Quaternion(0f, transform.rotation.y ,0f, transform.rotation.w);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question