Question by
anatomicgft · Dec 10, 2012 at 11:05 PM ·
scripting problemai problems
how do i get enemy ai to avoid objects in scene
the enemy ai in my game will follow my just fine but when i go behind an object or when a take a turn inside of a building then the enemy will just collide with whatever i am behind instesd of going around it what can i do to my script to prevent this.--here is my ENEMY AI FOLLOW script--- #pragma strict
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Comment
Answer by g7dme · Jul 04, 2018 at 06:09 PM
I am no expert but would you not normally use navmesh obstacle to deal with this exact situation ? although i have no idea how to implement this in code.
De Bob
Your answer
Follow this Question
Related Questions
unity isn't recognizing quaternions 1 Answer
Keep getting Null reference error for AI Script 1 Answer
Flying ship AI 0 Answers
AI Problem. 0 Answers
Disable a Function when another and active (javascript AI) 1 Answer