NPC stuck behind wall

Hello sir, I have written simple AI code for NPC to follow my player. It works fine very well and NPC always follow my player all over the map. But when my player is behind the wall or house then NPC doesn’t recognize it and tries to reach my player through the wall or house. Since collison detection is enable so NPC doesn’t pass through the wall or house and stuck there itself. when I am removing physics from NPC, it reaches my player by penetrating the wall or house. I stuck here please help me how to fix it. Below are the screen shot for more clarity. Many thanks

I see 2 possibilites here:

a) your NPC wants some privacy.

b) your “simple AI code” is too simple. is it possible it’s trying to run towards the player in a straight line, without any checks for objects in between?

EDIT: don’t let collision detection fool you, it won’t tell the npc to run around, it only stops it from running through walls.

Hi NetSky i think u didnt understood my question. Anyway thanks for the reply. For more understanding I pasted my AI code below please help me where I am doing wrong.


Blow line are part of my simple update method

[java]// AI code
Waypoint wayPoint = navi.getNextWaypoint();
if(wayPoint == null) {
System.out.println("wayPoint = " + wayPoint);
Vector3f vector = wayPoint.getPosition().subtract(npc.getLocalTranslation());
// Vector3f vector = wayPoint.getPosition();
System.out.println("vector = " + vector);
if (!(vector.length() < 1)) {
else {