- Home /
My Eneny AI Script Wont Work?
Hey, here is my script for my enemy ai
UnityEngine.Transform
UnityEngine.Renderer
var Distance;
var Target : Transform;
var lookAtDistance = 17.0;
var attackRange = 10.0;
var moveSpeed = 3.0;
var Damping = 4.0;
function Update ()
{
Distance = Vector3.Distance(Target.position, Transform.position);
if(Distance < lookAtDistance)
{
Renderer.material.color = Color.green;
lookAt();
}
if(Distance > lookAtDistance)
{
Renderer.material.color = Color.blue;
}
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);
}
Answer by eeveelution8 · Jun 23, 2014 at 03:26 AM
I made a tutorial with a simpl Ai with path finding here. http://forum.unity3d.com/threads/simple-ai-pathing-and-patrolling-set-of-scripts.253235/
Answer by Reafy · Oct 08, 2014 at 12:44 PM
If you still need it go to unity's website or youtube channel and look up NavMesh. Its usually alot easier than scripting
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
How can an enemy deplete players health? 0 Answers
Keep track of every time an int changes, including what the value is each time? 2 Answers
How to detect - as an enemy - if a fellow enemy next to you is in combat with the player? 2 Answers