x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Stop friendly-fire between enemies

Hello, I'm creating a game for practicing and learning porpuse. The thing is the enemies walk to me and attack but if another enemy is next to the one attacking me he get damaged too.

I tried to "filter" the attacker in the Apply Damage node by the Instigated by pin but I can make it work.

I have my character done in an actor BP and there is 2 types of enemies, that are childs of my character BP.

I someone needs I'll post screenshots of my BP, just ask for what you need to see.

Product Version: UE 4.20
Tags:
more ▼

asked Apr 20 '19 at 12:34 AM in Blueprint Scripting

avatar image

Sergioz93
6 1 1

avatar image Nebula Games Inc Apr 20 '19 at 01:06 AM

Screen shots would help. But from the sound of it, you seem to have the error of making your enemies children of the player character. So overlap events or hit events where you cast to "player character" will also fire if the child enemy is overlapping/hit.

avatar image Sergioz93 Apr 20 '19 at 01:18 AM

Yes, I know it's not the best to create those childs. Here I attach 2 screenshots of the "SwordMesh" (where the sword damage is coded) and "ProyectilMesh" (where the magic damage is coded). alt text alt text The Apply Damage node is coded on MyCharacterMesh.

sword.png (160.3 kB)
magicdamage.png (107.7 kB)
avatar image Lardo Deepdelver Apr 20 '19 at 10:23 AM

Use PrintString to find out if your instigators are set correctly When I look at the screen shoots sword has no instigator connected when i look at the magic damage you take the controller of the instigator? Is that instigator set correctly.

And this will apply damage, which you then need to filter out on the damage receiving side, something like this

alt text

That will not let any damage through done from a controller (your ai controller) to a same controller. If you have multiple types of ai controller it's a little bit more complicated, would suggest checking for player or Ai controller in that case

avatar image Sergioz93 Apr 20 '19 at 11:15 PM

Well, this last answer hit the nail. I added a instigator in the "sword" BP calling the "Instigator" actor variable and pass it to "get controlled pawn".

Then I added your code in my 2 childs BP and it worked like a charm.

You're a god, I spent 2 days trying to make it work but I couldn't. I was comparing classes like you suggest but for some reason I was failing.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I had a similar concern and here is how I dealt with it (please note that I am a beginner with UE4 BP scripting as well) :

What I would do is have the base class (`Character BP` in your case it seems) have a boolean IsEnemy. Then your various implementation inheriting from your base class will set the boolean as true or false depending if it is an enemy, the player, a friendly npc...

Use the instigated by pin as you yourself suggested and get that IsEnemy boolean and compare it to the class that is hit. If they are not both enemies or both allies, proceed to apply damage.

That looks a bit like this (in my case they all are GameCharacter's and this class has the IsEnemy boolean) :

alt text

You could encapsulate it in a function you call each time you try to deal damage and bypass it for the events for which you don't want to ignore friendly fire but that may be out of scope of the question.

I would recommend that you do NOT make your enemies inherit from your (Player)CharacterBP (as it seems to be the case currently if I understood well) but rather from a neutral class both your PlayerCharacter and your EnemyCharacter would inherit. It would work anyway but that design may limit your options and cause trouble later.

more ▼

answered Apr 20 '19 at 04:00 PM

avatar image

N0rgannon
22 1 1 4

avatar image DonBusso Apr 20 '19 at 07:24 PM

Hello I had the same problem with my AI dealing damage to one another when trying to shoot me. This is how I solved it.

Top part is for projectile the bottom part is inside my AI's blueprint.

Projectile passes over the Controller responsible for firing a projectile. When receiving damage the AI checks is Player is the instigator and when true damage is being applied. Crude but works for me.

Newbie style coding, sowwy.

https://imgur.com/a/nn6UnCo

avatar image Sergioz93 Apr 20 '19 at 11:19 PM

Hey guys, I already found an aswer that is currently working (Lardo Deepdelver provided it) but I just want to say thank you for taking your time and trying to help me.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question