Hi ! I got a problem. Surfed the web a lot to find a solution, But I don’t know, i tried so much possibilities and variants, and it still doesn’t work !
I’m trying to make a gameObject ( a creature ) rotating to look at me and then moving towards me.
Here’s my code, I really don’t understand why the creature doesn’t turn to me.
Sorry for bag english grammar, I’m french c’:
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
//Déclaration des variables
bool joueurVu = false;
public GameObject joueur;
float mouvementSpeed = 2.5f;
// Use this for initialization
void Start () {
joueur = GameObject.Find ("FPSController");
}
// Update is called once per frame
void Update () {
if (getDistance () < 10) {
joueurVu = true;
print ("Player seen!");
}
if (joueurVu) {
transform.position = Vector3.MoveTowards (transform.position, joueur.transform.position, Time.deltaTime * mouvementSpeed);
transform.LookAt (joueur.transform.position);
}
}
//Autres méthodes
float getDistance(){
return Vector3.Distance (joueur.transform.position, transform.position);
}
}