I have navigationagent2D on my enemy, and I placed navigationregion2D in my level. Everything was working fine, and my enemy was patrolling between 2 points. But then I added collisionShape2D to my enemy so he can get hit by the player. Now collisionshape2D causes conflict with it, it blocks it, it overrides it, I don’t know really what is happening. I’ve been trying for a while to figure it out. Disabling the floor mask makes the enemy patrol again. But now, after playing with it for a bit, even disabling the floor doesn’t work anymore. How can I get these 2 to work together and not conflict?
Bodies (like CharacterBody2D) with collision shapes and correct physics layers assigned to them can only collide with each other. If you want to check if the player is in the zone of your enemy’s attack range then add an Area2D to the enemy scene and add a collisionShape to the Area2D. And connect Area2D signal body_entered and body_exited to your enemy script and write some code so the player can loose health if you want. The signal will be emitted when player enters the collisionShape of the Area2D.
This is not what I asked. My problem is that I have navigationagent2D, navigationregion2D, and collisionshape2D. My navigation moves my enemy by patrolling between two points. This works, but when I added collisionshape2D to my enemy, it now breaks the patrol. So, I need to know what is causing this. Navigation doesn’t behave the same as characterbody or collisionshape, from what I saw. It doesn’t have mask layers or anything. The only thing I saw was parser mask, but it doesn’t seem to work when I play with it.
So, if you remove the CollisionShape now then the navigation doesn’t work, like you wrote? Have you moved your enemy position in the enemy scene after adding the CollisionShape? From my experience, you should have the enemy node’s (CharacterBody2D) position within the navigationRegion when you instantiate it in the prototype scene. Because enemy node’s (CharacterBody2D) position is the point from where the navigationAgent moves the enemy in your case. (You can see navigationAgent’s path when you enable debug option in the navigationAgent.)
I think the enemy moved down to be within the NavigationRegion, because of the bad navigationAgent’s point, and when you enabled the floor mask it got stuck? I might be wrong because I don’t know how the player is set up if you could have spotted it from player’s view.
if i disable floor mask then enemy can patrol but he falls into the floor, his not standing on it. if I enable it, something block the navigation and not letting enemy move at all, this happened after I added the collisionshape so it does something to it. and it don’t matter where I place my enemy, I can place him above the floor 15 meters away and he will just patrol in mid air. but what you said about bad navigation point and enemy get stuck might get me something to look at. if the point is under the floor and when I disable the floor, enemy falls into it to start patrolling then it could be it, even when I see region above floor as image shows. so by enabling floor mask, the floor block the enemy from going down. i will take a look
I managed to fix it. The problem was that the navigation region2D was too small. So, I increased it to cover the whole platform and some empty space. now the enemy is patrolling and player can also shoot enemy and hit him.