(SOLVED) [3D] Pathfinding object cannot path if destination is against a wall

Problem

Hello, I am making a 3d game and have an issue with pathfinding. I have an enemy that pathfinds to the player often, but if the player is hugging a wall, the enemy freezes and is unable to move to me. It seems like the enemy is thinking the player is inside the wall and unable to go there. In addition, the enemy does NOT have this problem if the player is hugging a certain face of a wall.

The image below shows me hugging a corner and the enemy stops. (the green thing is a map node where the enemy goes to if he can’t find me, they’re not the problem)

What is the expected result

The enemy should not get confused and pathfind to me whenever he is able to.

What is the actual result

Whenever I hug certain faces of a wall, the enemy freezes and does not move to me.

Related screenshots

The image below is the map. The parts highlighted in green is the walls i can hug where he DOES pathfind to me, and the ones highlighted in red is where he CANNOT move to me.


The eventing that has him pathfind to me. The game raycasts a line from the enemy to me to check if he can “see me.” If he does, he pathfinds to me. I have tried removing the raycasting and the problem is not fixed.

I really want this fixed since most of the game mechanics will rely on pathfinding and I don’t want the game to be cheesable.

I don’t have much experience in 3D but it seems to be the same as with 2D.
Is the enemy larger than the player? If the player is a camera not an object than I’m assuming the camera can get closer to the wall than the enemy.

The default origin is in the upper-left corner (0,0) This example uses 2 objects. With the origin in the top-left corner. It works on the 1 side because the target point is against the wall. So, the enemy will fit. But when it’s in the other places, the enemy won’t fit.

This is a drawing. You can see where the purple object can move. The orange can’t fit when the X,Y is in the top-left corner without hitting a wall. So, it won’t move.

Using a camera that could hug the wall closer than that would make it even worse.

I don’t know how to fix this in 3D. In 2D, I would make sure the objects were the same size and shared the same point location. Or I would use a smaller object for the pathfinding. A smaller object could get closer and stick a larger object on top of it. The object center points would all be in the center.

Another option would be to prevent the player from getting too close to the wall.

The first approach would cause the enemy to go into walls because the orange isn’t used for the pathfinder collision. A smaller object the same size as the player would be in the exact same spot as the player, the purple square.
while the 2nd would keep the player from getting too close to a wall.
They both rely on using the center of the object or X()+width/2, Y()+height/2

Again, I’m not sure how to apply the fix in 3D. It’s all about making sure there’s enough room for the enemy to completely fit in the target location.

I am using the 2D pathfinding behavior, so it doesn’t consider the elevation position. Nothing ever changes elevation either, so there will be no problems with elevation. Thus, it works exactly like 2D pathfinding!

I should have clarified that the Camera is an object and not an actual camera. I built the game off of the 3D First Person template (which is already pretty bad LMAO) and the player is labeled as “Camera.”
image

The Player and Enemy do not have the same dimensions. I would love to be able to edit collision boxes but unfortunately I cannot.


However… you were correct! You said that the sizes might be the problem, and you were right. I changed the player to a width of 128 instead of 64, and the enemy was able to pathfind to me. It’s gonna feel weird with the player being a bit fat, but I can’t resize the enemy without the sprite being heavily altered. I wish 3D collision masks and points and animations existed…
Thanks for the help!

1 Like