Not sure how to handle collision on my NPCs

Hello,
I am currently working on my enemy AI and I use an EQS for it to find cover when runs out of ammo.
The problem is the NPC consider itself as something blocking the vision of the player, so he sometimes choose a grid point in his back as a cover.

The collision preset on my Enemy BP is set to blockAll so I can fire at it and block the line trace from the player weapon. But as I said, it causes the above issue with the EQS.

If I change the collision preset to Pawn for example, the EQS work as intended but I can’t fire at the NPC, the line trace is not touching the NPC.

I am not sure how to handle this issue, am I supposed to use blockAll and so find a way in the EQS to ignore NPCs ? Or an other collision preset for the NPCs and if so, how can I handle player shooting the enemy ?

Thank you

Hi, I would recommend adding your own custom collision object and trace channels. You can usually setup a trace by channel, and we can use this new one you create to only target any objects that block that channel. We can also make a preset that you can add to any object more easily.

To start, you’ll want to go to the project settings collision tab and then you can click New Object Channel and New Trace Channel. Make them both default to ignore for now.

Then you can make a preset and have it block everything except for Visibility for now, which is ignore (I’m basically reusing the Pawn preset but adding in the blocking collisions for your new channel). You can adjust this later if you need any collision tweeks later too.

Finally, you can change the collision preset on your pawn in the BP to use the new preset profile you just created.

Now once that is setup, you can line trace by channel, and that should only hit any object that is “blocking” the new trace channel you created.

Hopefully this gives you the desired effect you need.

thank you so much.
I did everything you posted and its working well and I understand the purpose. However I have other question if you dont mind.
If I trace the line on the HitNPC Channel, then I can only shoot ennemy NPCs. I have some FX set up like bullet holes and with this, I cant shoot into wall. So, what would be the good practice here, make every mesh with the preset NPCEnnemy ? Seems overkill and I dont think this is how I should do it.

Also, my Ennemy_NPC_BP consist of a Capsule component and a Mesh for the character. I set up the collision on the cylinder because it doesnt work on the mesh, the ennemy just goes trought the floor. I guess its because I have not set up a hitbox for the ennemy right ? I never worked with hitbox yet, I was using " use complex as simple " on all static mesh for now, but never with skeletal mesh.

Thank you!

If you want walls in the way, you may want to trace for the visibility channel instead. We will have to change the preset to block visibility as well. The other solution is to have your HitNPC trace channel default response be block, and you can adjust whichever collision preset to ignore that channel that you don’t want to be checked for a hit. (In this case probably the Overlap presets and Pawn presets)

The character falling through is probably because we set the default collision behavior to ignore. You can go into each preset that is supposed to block the new collision and change that behavior from ‘ignore’ to ‘block’ (If the Pawn collision is set to block on the preset, I would also change the one you created to that).

Collision can be a bit tricky when setting up a new profile or channel, but it helps in the long run for sure!

thank you so much, I fixed it :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.