Make the Hitscan ray clip through an object that's on a death animation

As the name of the topic suggests, I want to make my Hitscan hit registration system clip through an enemy once it’s on a death animation.

For context, I used this example as a guide on how to make one.

The problem is that the laser only makes contact with one enemy until it gets deleted. I tried to make it so that it only targets those with a specific animation but it still doesn’t work.

To give you an idea of what my events look like, here is the screenshot:

Because of this, I went for an alternative. I made several events where the laser only target specific objects. And while I did get what I want, it created another problem: Now, the laser (aka the Hitscan) makes contact with two different objects at once. It doesn’t matter whether the object is behind another and whether if both are still not in a death animation.

Here’s what I did:

Here’s what I want in a form of a scenario/example:

In this scenario, we have Enemy 1 and Enemy 2. Both are completely different objects.

They are going after the Player in a line formation (Enemy 1 in front and Enemy 2 in back).

When the Player fires his weapon, the Hitscan should make contact with what is in front of it first, that being Enemy 1 before going after what’s behind it, which is Enemy 2.

It should only be allowed for the Hitscan to clip through Enemy 1 once it’s on a death animation which at that point would target Enemy 2. Is there a way to do this?

My first thought is to make a second object with just the death animation.

1 Like

My first thought was using **nearest object ** but the nearest might be behind an obstacle. You can’t use for each object because that goes through the instances by order of creation.

You could create a list of objects by distance and give them an ID number and use that list or maybe set a boolean on each object like IsReachable if it’s not blocked and then use a condition to filter just the IsReachable ones. You could then use **pick the nearest ** from those picked objects.

If there weren’t too many objects it wouldn’t be too resource intensive.

It would be easier to do with Javascript, sort of like the object picking extension. It would be nice to have Pick nearest, pick next nearest or pick nearest by index. Or a way to sort the for each object with rules.

1 Like

Maybe I over thought your problem. If you’re just trying to ignore the first and shoot the 2nd then maybe if you check the animation first and then do the the ray cast or pick nearest. I guess it depends on how many targets you have. You might still need to go through the objects by distance.

I made an interesting tower defense example a while back. For efficiency, it used the health extension plus a temporary health. As soon as it was targeted the temp health was deducted. So, when a new target was chosen it would be ignored if the predicted health was zero. Should the projectile miss, the temp health was added back otherwise it was deducted from the real health.

In my example it fires from all 3 towers when you touch. The enemies are draggable.

It used the health to target the weakest. I believe I looped through to look for the one with the lowest predicted health.

I should rework it. I’m sure there’s a lot that I might do differently now but it still has some interesting concepts.

1 Like

The Hitscan is working properly now. Thanks!

I’ll think about this. Your method seems a little complicated, but I’ll try using them for my next game. Thanks BTW!

1 Like