FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionAI js Script

more_horiz
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

descriptionRe: AI js Script

more_horiz
Nice

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

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