Программы+языки

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Программы+языки » Скрипты » Аи турели


Аи турели

Сообщений 1 страница 2 из 2

1

Код:
var attackRange = 30.0;
var shootAngleDistance = 10.0;
var target : Transform;

function Start () 
{
   if (target == null && GameObject.FindWithTag("Player"))
   target = GameObject.FindWithTag("Player").transform;
}
function Update () 
{ 
   if (target == null) 
   return;
   // Rotate towards target 
   var targetPoint = target.position;
   var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
   transform.rotation = Quaternion.Slerp(
      transform.rotation, targetRotation, Time.deltaTime * 2.0);
// If we are almost rotated towards target - fire one clip of ammo 
   var forward = transform.TransformDirection(Vector3.forward); 
   var targetDir = target.position - transform.position; 
   //if (Vector3.Angle(forward, targetDir) < shootAngleDistance) 
   //SendMessage("Fire");
   Debug.DrawLine( transform.position, Vector3.forward*20, Color.red);

}

Теги: турели

0

2

Вот ещё скрипт турель, но другой

Код:
var projectile : Rigidbody; 
var shootAngleDistance = 10.0;
var bulspeed=700;
var target : Transform;
var reloadTime = 0.5; 
var ammoCount = 2000;
private var lastShot = -10.0;

function Start () 
{
   if (target == null && GameObject.FindWithTag("Player"))
   target = GameObject.FindWithTag("Player").transform;
}
function Update () 
{ 
   if (target == null) 
   return;
   var targetvelocity=target.rigidbody.velocity;
   var Distance =Vector3.Distance(transform.position, target.position) ;
   var targetPoint = Vector3(target.position.x+targetvelocity.x*Mathf.Sqrt(Mathf.Pow(Distance,2)/(Mathf.Pow(bulspeed,2)-Mathf.Pow(targetvelocity.x,2))),target.position.y+targetvelocity.y*Mathf.Sqrt(Mathf.Pow(Distance,2)/(Mathf.Pow(bulspeed,2)-Mathf.Pow(targetvelocity.y,2))),target.position.z+targetvelocity.z*Mathf.Sqrt(Mathf.Pow(Distance,2)/(Mathf.Pow(bulspeed,2)-Mathf.Pow(targetvelocity.z,2))));//Поправку берём тут
   var targetRotation = Quaternion.LookRotation (targetPoint-transform.position, Vector3(0,1,0));
   transform.rotation = Quaternion.Slerp(
   transform.rotation, targetRotation, Time.deltaTime * 2.0);
   var forward = transform.TransformDirection(Vector3.forward); 
   var targetDir = target.position - transform.position; 
   if (Vector3.Angle(forward, targetDir) < shootAngleDistance) 
   BroadcastMessage("Fire");
   //Debug.DrawLine( transform.position, transform.position+forward*1000, Color.red);

}
function Fire ()
{
if (Time.time > reloadTime + lastShot && ammoCount > 0)
   {
   var instantiatedProjectile : Rigidbody = Instantiate (projectile, Vector3(transform.position.x,transform.position.y,transform.position.z+20), transform.rotation);
   instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0,0,bulspeed));
   lastShot = Time.time; 
   ammoCount-- ;
   }
}

0


Вы здесь » Программы+языки » Скрипты » Аи турели


Рейтинг форумов | Создать форум бесплатно