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
Share
Go down
avatar
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 1280
Rep : 0
Join date : 2015-01-26
View user profile

AI js Script

on Mon Jan 26, 2015 10:42 pm
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
avatar
Moderator
Moderator
Posts : 329
Points : 2176
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: AI js Script

on Tue Apr 14, 2015 1:11 pm
Nice
Back to top
Permissions in this forum:
You cannot reply to topics in this forum