- Home /
Enemy AI passing through walls
Though I have some tutorials and answers regarding enemy passing through walls but still didn't get it how to stop it? And so now I am attaching scripts. I know something should be added around the setdestination line but what??
void Update()
{
float distance = Vector3.Distance(target.position, transform.position); //x,y,z distance between target position
//and our position
if (distance <= 60f)
{
agent.SetDestination(target.position); //enemy will start chasing our hero (animations here)
if (distance <= agent.stoppingDistance)
{
FaceTheTarget(); //face the target
if (Time.time >= nextFiringTime && bulletreloadtime>0)
{
ShootTheTarget(); //attack the target (animations here)
nextFiringTime = Time.time + 1f / 7f; //set timing intervals of enemy fire
bulletreloadtime--;
}
if(bulletreloadtime==0)
{
bulletreloadtime = 40; //bullets are reloaded
nextFiringTime += 2.5f; //bullet is reloading, time for reloading
}
}
}
}
Hi, are you sure you created the Nav$$anonymous$$esh right with all the walls with Nav$$anonymous$$eshObstacle component?
yaa I didn't know about this. Now it is working fine. Thanks!
Answer by Bystander333 · Jul 30, 2018 at 05:01 PM
This doesn't sound like a code problem. Check the walls are baked into the navmesh in the Windows->Navigation window. Select the walls and check the Object tab.
Your answer
Follow this Question
Related Questions
Questions about movement on uneven/slopped terrain and terrain coliders 0 Answers
Raycasting on Moving Colliders 0 Answers
Moving objects using raycasting? 1 Answer
Making object found with raycast a child of the object the ray is cast from 1 Answer
Move player to specific location and avoid obstacle. 2 Answers