Enemy applies damage to me on overlap with my weapon's collision box

I’ve got a bit of a noob question here: I’ve got a simple melee system in place using a collision box component in my character’s blueprint that I activate, get overlapping actors (to which I apply damage), and then deactivate. It’s all working so far (though I have aims to figure out a way to have the weapon out for longer than just an instant and apply damage to any and all enemies that touch it during that time, but that’s not what I’m trying to solve right now).

The problem popped up when I tried to implement the system for taking damage myself. I got an enemy up and running that does damage to me when I run into him, and that works fine. The issue is that when I attack with my sword and activate the sword’s collision box to take an overlap reading and apply damage to the enemy, the enemy takes that same overlap event as an excuse to apply damage to me as well. It thinks that I just ran into it, even though it’s only overlapping with my blade.

I need to figure out a way to get the zombie I’m attacking to tell the difference between my character’s capsule and my sword’s collision box so it can only apply damage to me when it overlaps my capsule and not my weapon, too. Any ideas?

In your Project Settings, you need to make a new collision channel for your sword aswell. Having a Pawn and a Sword collision property you can set which of them will collide with each other or not.

For example you can set Swords to ignore each other’s collision and only overlap with Pawns. Don’t forget to change the swords’ collision settings aswell. :slight_smile:

Ah, sorry, I misunderstood your problem so my answer had no meaning.

Though if you got 3 channels, it supposed to work. If your sword is ignoring Pawn Channel but not Zombie channel, your sword would only hit the Zombie channeled collisions. Also if your Zombie is set to only overlap with Pawn, then it should be ok.

Can you show your collision properties of your player, enemy and zombie? Seeing the pictures might be better not only for me but for other people want to help aswell. :slight_smile:

Also you can use traces aswell and this is the most precices way that you can check if the sword is hitting. Upside is you can chose to ignore meshes, including yourself, or owner etc.

Just a note, you can also use the component-part of the Begin Overlap aswell. By this way you can get the component and compare if it’s equal to Player Mesh, instead of getting the whole actor. Make a branch and after the “true” part, get player character 0 (assuming you got no other player) and cast to it to apply damage. As you see, the only difference is now you are comparing the component instead of the whole actor, at the beginning. :slight_smile:

This might be a work around, though I still believe we can fix your problem with only collision channels.

I have three custom collision channels set up already: player, weapon, and enemy. I’m not sure how it could be all about collision, though, since if I were to set the zombie’s “weapon” collision detection channel to ignore, he does just that, and I’m unable to hit him. It’s set to overlap now because that’s what I want it to do, and it does indeed generate overlap events, because that’s part of the problem: if it didn’t generate overlap events, I wouldn’t be able to deal damage to him. It’s just that, at the same time–and because of that very same overlap event–he also deals damage to me.

On my zombie blueprint, I’ve got it dealing damage to the player with an “Event Actor Begin Overlap”, a “Cast To HeroCharacter”, and an “Apply Damage”. All I need it to do is to NOT apply damage when the overlapping component is the sword component of my HeroCharacter. I’ve tried to do this by dragging off the “other actor” pin on the “Event Actor Begin Overlap” node and running it through all kinds of checks and branches, but it doesn’t matter, because when I “Print Text” the result of “Get Overlapping Components”, it returns the exact same thing whether I run into the zombie or hit it with the sword. The engine just can’t tell the difference.

So that’s the problem I’m running into. How do I get the engine to attach the sword collision box to my character without making it a component? If I could find a way for the sword collision box to appear to the enemies as an altogether separate actor than my HeroCharacter, then I could set a different reaction to it, and I’d be golden.

This is a surprisingly basic thing to get hung up on, but all of the tutorials on melee combat that I’ve seen either show how to deal damage to enemies, or how to have enemies deal damage to the player, but I haven’t seen one tutorial that does both. Amazingly, it seems that the common ways to do those two things are in direct conflict. I must be missing something really obvious.

Here’s an album of pictures with the collisions. I’ve been ticking all the different boxes trying to get the results I need, but it seems that they don’t really do what I expect them to most of the time.

I’ve been experimenting with different ways of doing collision since I first posted. I added a CubeMeshSwordOverlap to my HeroCharacter components list and attached it to a socket in his hand. When I attack, the animation I made will swing it out and it’ll collide with the enemy. Sadly, it’s doing the exact same thing as the collision box did. Which is to say it works, but the zombie still can’t discern a difference between it and my hero. Any component of my hero will be treated the same, I guess.

Tell me more about this method of using traces, please. I’ve seen the concept bandied about a few times, but I haven’t found a tutorial. If I can deliver damage without any part of my hero coming into contact with the enemy, I could sidestep this whole issue.

My goal is to have the sword deal damage to all enemies it comes in contact with (not just the first one it runs into) in case there are several bunched up together, and to deal damage to all enemies it collides with over the course of the whole animation, not just whichever enemy it hits at the instant I press the attack button. I don’t know if the trace method will allow for those things, but I hope it does.

What is your setup? when you hit something you can get all kind of data, like hit actor, hit component, with this you should be able to tell what you are hitting.

Alright lets see.

Your Capsule component has the collision type of Pawn and it ignores Weapon, seems fine.

Your Mesh, player character mesh, while having the “no collision preset”, its still overlapping with the Sword collision (you can see the tick there). Make it exactly same like you have done the Capsule. Don’t let it overlap with the weapon. Note that when you create a collision type, you need to go Project Settings - Collision tab again and select “nocollision”. Then press Edit to make sure those new types are ignored aswell. :slight_smile:

Your both mesh and capsule component is generating overlap events though. You may want to let only one do it, just for now and tesing purposes. For example use Capsule for now and don’t let the Mesh cause any overlap events to trigger.

Swordoverlapbox (assuming this is the box component you have created for overlap), is not generating any overlap events, why not? Ins’t this the component you want to have overlap events when it touches something? And it supposed to not ignore Enemy, it supposed to overlap =)

CubeMeshSwordOverlap (assuming this is the mesh), should not block enemy. Make it ignore just for now. To be honest since I cant see the viewport and both items have overlap on their names, its abit hard to understand which one is which.

Your zombie is blocking the sword, try making it ignore the sword aswell just for now.

Do not use meshes for overlap events. Using “mostly” capsule components is better for accuracy. First of all fix your “Sword overlapping mesh” problem, then go for the enemy one.

Best way is to make sure everything ignores everything (not static though, your character falls down otherwise) and make your Sword overlapping collision component to ignore Pawn and overlap Enemy. Make Pawn İgnore Sword and make Enemy ignore Sword aswell and see if it works.


About traces I can’t really help for I didn’t work quite alot. But you can use multitraces to not let trace finish when it finds a target. =)

Okay, I’ve followed your advice, but it doesn’t seem to have done anything. Actually, I’ve found that even turning every single collision response to “ignore” on every single component of every single actor still doesn’t do anything. Even WorldStatic is ignored, but I don’t fall through the floor. I’m compiling and saving after making the changes, but they’re not taking. Though… sometimes they do take, so I know I’m editing the right blueprint. Earlier today, I’ve been able to set everything to ignore, fall through the floor, then set it back to block, and be able to walk around again. It’s just that I haven’t been able to figure out why it’ll work sometimes and not other times. I’m thinking it’s just really buggy.

But I feel that it’s sort of besides the point. Are we sure that the collision response is really the problem here? Like I said before, the melee combat is working. I’m able to send and receive damage to the zombie through overlap events that I’m driving. It’s just that, logically, if I’m overlapping the zombie, then the zombie is also overlapping me; that’s why I both send and receive damage from the same event.

Even if the engine weren’t being so buggy and would let me set collision responses, it’s already detecting and responding to the sword’s collision the way it should be. From debugging it, the zombie literally cannot tell the difference between my capsule and any other component of the HeroCharacter, and I think that’s the real problem.

I have to figure out how to either force the zombie to recognize that the sword is a component altogether separate from my capsule, or script the way I take (or deal) damage from (or to) the zombie a whole different way.

Thanks so much for your help so far, by the way!

Yeah, it looks like whenever I want to change the collision responses, I have to make the changes, then save the blueprint, then delete every instance of it in my level, then repopulate it with them. Then they’ll finally use the new collision settings.

I know what you’re thinking, but if I’m inadvertently editing a given instance of the blueprint instead of the blueprint class, the changes wouldn’t propagate when I made new instances, would they?

Anyway, I haven’t figured out my real problem yet, but stay tuned.

It’s quite strange that the collision updates after you delete and put actors back again. I never had such problems. o:

Anyhow, I am sure someone with more experienced eventually come and help! Good luck. :slight_smile:

Well hey, I guess I don’t need the problem solved anymore since I’ve graduated to using a “Multi Box Trace by Channel” method instead. Again, it sure is weird that such a basic implementation of melee combat (overlapping) would have such a glaring impasse as soon as you try to combine it with enemies that can damage you as well. Oh well, this trace method is going to work even better for my purposes anyway. Thanks!

While I know you could eventually fix the overlap problem, it’s quite acceptable to use traces aswell, precise, easy to debug, easy to ignore owner etc. That’s what people have done at UDK times. =) Good luck!