Hello once again, I need help with trying to create a foundation for a system of dealing damage to the player via collision with a enemy. Right now I’m not trying to make anything fancy, just for a Print String to display the message “hurt” when the player comes into contact with the test enemy I’m currently working with.
To accomplish , I’ve been trying to use a variation of the setup I used for Jump Collision but I’m having problems with getting a reference to the player’s capsule component so that it can interact with the enemy’s own capsule component. The screenshot below shows a capsule component hooked up to my setup but I’m not entirely sure whether or not it is the player’s capsule component or the enemy’s, either way the current setup doesn’t work at all.
I tried without getting a reference to the player’s capsule component & just ran the events directly from the Cast to Player BP which actually did work, but unfortunately, my player character also has a couple of other collision boxes attached to it which ended up causing a different problem. new problem was that attacking the enemy would trigger the “hurt” message, which is why I need to limit the enemy’s collision to specifically the player’s capsule component and not any of the other collision boxes attached to my character.
Does anyone have any ideas on how I get to work properly? Thanks in advance!
EDIT: I was also wondering if I can’t directly reference the player’s capsule component from within the enemy’s blueprint, then is there some way that I indirectly reference the player’s capsule component by creating some sort of event within the player’s own blueprint that can communicate with the enemy blueprint?
You can create custom collision channels in Project Settings->Collision if you want to stick to kind of coarse collision but still be able to differentiate between different parts of a single pawn.
Alternatively you could use a hit event which I find to be a little more reliable for kind of thing. and then cast to the player whenever you hit something (better ways to do but for example is simple) and fire a custom event in the player that handles whatever logic you want.
Sorry forgot to address the multiple collision boxes. If you put a check in like that will stop it firing except when it hits the capsule.
Actually after thinking about it for a few more seconds I think using the damage system is a better option, that’s what it’s there for and the less you have to roll yourself the better.
So there’s some options for you, I would recommend the damage path though.
Thanks for the response, I’m not sure I’m not sure if I have something setup wrong or not but unfortunately it still isn’t working.
Something else I probably should mention which I’m not sure whether or not is contributing why your solution isn’t working is that the enemy is setup to pass through the player upon contact like in old school platformers like Mario or Sonic.
Here’s the enemy’s collision settings for their capsule component, just in case.
EDIT #1: I just noticed the part about checking the Simulations Generates Hit Events box, I checked the box but it hasn’t made any difference though.
EDIT #2: I just tried your initial suggestion but once again nothing has happened.
Ah right, yeah hit events won’t work in that setup because your collision response is query only, in that case you should be able to substitute overlap for hit.
You’ll want a to use the component overlap event you were using originally and just hook up the the wires to match the hit event and it all should just work. You’ll need to have the collision response of your enemy set as overlap for pawn (or whatever collision object type your player is) but it seems like you’ve done that already.
That got it to work, and the damage message doesn’t appear when jumping on the enemy like I was worrying… most of the time. Every now and then, the damage will appear and I hasn’t been able to identify a definite cause, though its most likely something to do with the size or the positioning of the jump collision in relation to the character’s capsule component. Although that’s an issue that probably falls outside the purview of topic and should be addressed in its own topic. Otherwise everything else appears to be in working order. So thanks for the help!
provided solution in the comments below:
Ah right, yeah hit events won’t work
in that setup because your collision
response is query only, in that case
you should be able to substitute
overlap for hit.
You’ll want a to use the component
overlap event you were using
originally and just hook up the the
wires to match the hit event and it
all should just work. You’ll need to
have the collision response of your
enemy set as overlap for pawn (or
whatever collision object type your
player is) but it seems like you’ve
done that already.