Advertisement
Guest User

SimpleAi

a guest
Oct 2nd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. public class SimpleAI : MonoBehaviour {
  2.  
  3.     private Transform Player;
  4.     public float velocidade;
  5.  
  6.     void Start(){
  7.  
  8.                             //Encontrar gameobject apartir de uma tag- transform pra pegar a posicao
  9.         Player = GameObject.FindGameObjectWithTag ("Player").transform;
  10.         if (velocidade <= 0) {
  11.             velocidade = 5;
  12.         }
  13.     }
  14.  
  15.     void Update(){
  16.         controleDaDistancia ();
  17.     }
  18.     //Controalr distancia do inimigo e player
  19.     void controleDaDistancia(){
  20.         float distanciaAoPlayer = Vector3.Distance (transform.position, Player.position);
  21.         print (distanciaAoPlayer);
  22.         if (distanciaAoPlayer < 100 && distanciaAoPlayer > 1) {
  23.             seguirJogador(true);
  24.                 }
  25.         else {
  26.             seguirJogador(false);
  27.         }
  28.     }
  29.  
  30.     void seguirJogador(bool seguir){
  31.         if (seguir) {
  32.             Vector3 Direcao = (Player.position - transform.position).normalized;
  33.             //print (Direcao);
  34.             //Qualquer coisa tentar adicionar transform.foward
  35.             transform.position += Direcao * Time.deltaTime * velocidade;
  36.             //Variavel q recebe valores de rotaçao
  37.             Quaternion olharPara = Quaternion.LookRotation (Direcao);
  38.             transform.rotation = olharPara;
  39.         }
  40.         else {
  41.             return;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement