Stop projectile from damaging self in Multiplayer

Hello,

I’m building a small cooperative multiplayer game where I would like to use physical projectiles and have friendly fire enabled. The issue is that the projectiles will automatically collide with the character upon spawning. I can solve this by using a Branch to see if the Overlapping Actor = the Character, but this makes all other characters invincible.

Currently I have my Character Blueprint which Spawns Weapon into the character’s hand, and I cast to the weapon to say “Fire” and the Weapon Blueprint spawns a Projectile Blueprint. So basically, Character > Weapon > Projectile.

What I did to prevent from shooting myself, but still being able to deal friendly fire damage, was this:

But I’m left with 2 issues.

  1. A player can still hit themselves if they’re moving fast enough or something.

  2. You still won’t be able to hit other people if you’re all stacked on top of each other or really close to each other.

There has to be a better way, but I just don’t know.

I would sincerely appreciate any input or guidance provided.

Thank you,

-Metric

Hey MetricZero, just from looking at the screenshots it looks like you need to plug in the reference to OtherActor as the damaged actor.

I’m not 100% on this, but I’m pretty sure apply damage will damage the actor that calls it if the Damaged Actor reference is NULL

Here’s a screenshot to help out.

To prevent damage from being caused on the owner of the projectile, make sure that when calling the SpawnActor(ProjectileClass) method, you plug in a reference to your owner. The fact that your projectile is not damaging players if they are stacked on each other is likely due to your projectile being spawned too far away from your owner causing it to start too far away from anyone to create a hit event. Overlaps can be tricky especially when the actor is first initialized in the world. I’ve had issues with overlaps not calling if two actors spawn on top of each other.

You can check this box here to true and call a hit event as well. In my use cases they tend to be more reliable for projectiles.

You can also use timers that call every .1 seconds (slower than tick, but fast enough to call before anyone notices) to check overlapping actors. As soon as the index is valid, I clear the timer and run whichever method I want.

This isn’t the best for projectiles as it can be a bit heavy, but if moving your spawn transform closer doesn’t help then this is probably the best way to to do it.

I hope this helps!

1 Like

Oops, you’re right. I redid my nodes for the screenshot and forgot to connect Other Actor to Damaged Actor.

I think I found a solution that works for me. I spawn the bullet inside of the character’s collision and it sets that as the first hit actor and ignores it, but continues to damage everything else.

I can’t understand how replication works with my artist brain yet. The only way I can fathom of getting the player controller who fired would be by sending the reference down 4 layers of abstraction from PlayerController_BP > Character_BP > Gun_BP > Projectile_BP and even then it won’t work properly because the server.

You said plug a reference in to the owner but technically the server owns everything. It’s the server who spawns the projectile and the gun but the character is controlled by the pawn. At least I think? I’ve been through so much documentation and done the available tutorials multiple times and it just still hasn’t clicked for me.

Edit: Lol, I forgot to plug the Damaged Actor in again for the screenshot.