Basic enemy AI

I adjusted the rotation code a bit.

You can replace the script or the UpdateMovement function.

Please let me know if this solves your issue.

I observed him for a few minutes, he did not get stuck in back and forth, I also teleported him to the small spawn area multiple times and he kept getting out without getting stuck. The only door he was not able to get through (I think) was this door, I took pictures and 3 different angles so maybe you could see why, could you also tell me what you changed about the rotation? It definitely seems a lot better!



Let me rephrase, He CAN go through the door, (i just saw him do it) but it seems like it is difficult for him to enter that specific door

@Albertos I just added ignore tags to doorframes too, and made it so he does not ignore the open door because it looks like he goes through it like a ghost, even then he still loves the electrical room, he wont even go the the left side of the map, and I have the patrol range really high

It sounds like a limitation of the lack of pathfinding. You actually just have to be lucky that the AI ​​will find a way through the obstacles. It may happen that the AI ​​will repeat a path indefinitely. To get out of here, either the destination or the obstacles must change. Fortunately, this also happens in most cases.

1 Like

Thats it! What if it dedtects if trapped nd changes destinations? Something like that!

How do you think you can detect that (without using a big script)?

1 Like

Velocity? I also had another idea, if the player gets to far from the ai, it will teleport somewhere closer but out of the players view, or something like that…

No, because the AI still moves.

You can simply change the position for the random destination. By default it’s using the origin of the enemy at start, but you can change this for example with the position of the player. It’s done in the Patrol state.

1 Like

Great, how do I make sure the random position is not outside the map, (i am guessing I can’t)

There is no way to prevent the random position is outside the map, but as the random position is changing every couple of seconds and the AI cannot move outside the map, I don’t think this is a problem.

1 Like

Ok great, and how do I set ranges, like random position can not be () away?

It’s the patrol range attribute.

So thee guy does not move

this.SetRandomDestination(0, this.patrolRange);

Why you use 0?

That should be the position of the player (by default the origin of the enemy).

1 Like

Ohhhhhhhh, So the enemy is always nearby!

Then you should use the position of the player in combination with a lower value for the patrol range attribute.

1 Like

This? this.SetRandomDestination(target.getPosition, this.patrolRange);

I don’t think there is a target in the patrol state, so I’m afraid you need to define the player entity yourself.

Also it’s getPosition() instead of getPosition.

1 Like

How? the target systems uses tags instead of attributes, I no nothing about tags