Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » AI js Script

AI js Script

View previous topic View next topic Go down  Message [Page 1 of 1]

1 AI js Script on Mon Jan 26, 2015 10:42 pm

Beast Coder


Member [Lv. 1]
Member [Lv. 1]
AI script
Code:
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;

function Update ()
{
   Distance = Vector3.Distance(Target.position, transform.position);
   
   if (Distance < lookAtDistance)
   {
      renderer.material.color = Color.yellow;
      lookAt();
   }
   
   if (Distance > lookAtDistance)
   {
      renderer.material.color = Color.green;
   }
   
   if (Distance < attackRange)
   {
      renderer.material.color = Color.red;
      attack ();
   }
}

function lookAt ()
{
   var rotation = Quaternion.LookRotation(Target.position - transform.position);
   transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}

function attack ()
{
   transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}

feel free to edit the values of the variables

this has been imported from another project of mine so it might have a few errors Embarassed

tell me if there are any errors! Smile

View user profile

2 Re: AI js Script on Tue Apr 14, 2015 1:11 pm

developer23


Moderator
Moderator
Nice

View user profile http://masterdevelopers.altervista.org/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum