Download

Ignore certain enemy's in sphere trace

Hello!
Iam new to unreal engine. I hope I posted this in the right section.
Right now iam creating a game, where Ai controlled soldiers defend their base from zombies.
The AI Aggression is based on a sphere trace and a closest enemy calculation. Everything works fine. The soldier kills a target and smoothly sets a new target and kills it. The problem is, when I create a soldier with a high attack speed it’s not that smooth. Sometimes the sphere trace targets the same zombie enemy and he just waits until the death animation ends and the zombie is dead.
I already tried to include a branch with a health <=0 check, but the problem is the same. I also created an array and added each killed zombie to it, to ignore killed zombies In the next sphere trace. This works for 2-3 enemy’s until the sphere trace keeps including ignored targets. I don’t know why and I don’t know what else I could try.

Screenshot? Also sorry to be the grammar police but its enemies not enemy’s, unless your talking about an enemy’s sword/armor/whatever. Also, print string is your friend. Output the actor name and health of actor to see whats up, with some spaced out individual enemies and a single unit.

Hello there,

I’m not sure why the solutions you described have not worked, but there is another possible answer to stop the sphere trace from detecting the enemy at all.

First, check what channel your Sphere Trace is: visibility or camera (if it is Sphere Trace for Objects, then what object types are you tracing for?).

Then, when the enemy dies, change the collision on the enemy (any components on the enemy that have collision) so that they ignore whatever channel the Sphere Trace is searching for.
This way, the sphere trace will not detect them.

For example, say you are using a sphere trace for the Visibility channel. When an enemy dies, the enemy should get their capsule component and mesh and for both Set Collision Response for Channel. Choose “visibility” and choose “ignore”. Of course, your situation might be different than this example.

A slightly easier way would be to Set Actor Enable Collision to false. However, this would not work for a character because then the character would fall through the ground. This would only work if your enemy was a pawn.

Im saying print string to tell where its messing up to potentially find why its messing up. The most obvious solution would to be just detect if hp is equal to or below 0