Line tracing for jump collision

So for a while now I’ve been trying to implement the ability for my character to defeat enemies by jumping on them a la the Super Mario games. My initial approach was to attach a hit box to the underside of my character. The problem with approach though, is that the jump hit box has responsiveness issues resulting in my character occasionally taking damage from jumping on the enemy. I tried a variety of things to improve the response time of the hit box but no matter what I tried, I could only reduce the frequency at which the player took damage and not eliminate it completely.

Because of I decided to scrap the jump hit box & take a new approach by instead using Line Tracing, following [][1] tutorial I found on YouTube. The problem though is that I’ve never used Line Tracing before and the tutorial is very basic, only covering how to set up the Line Tracing itself and not the more complex interactions between the player and enemy needed for the player to deal damage to the enemy without damaging themselves in the process.

Unfortunately, I don’t know how to set up said interaction, with the jump hit box it was simply a matter of calling up a reference to the hit box in the enemy’s blueprint as exampled below:

But how do I call up a reference to the jump line trace in the enemy blueprint? The line trace is set up in the player’s blueprint, and to my knowledge you can’t call up references to line traces because it is not a component. My initial thought about was to use a custom event but I’m not sure how to implement a custom event within setup:

Can anyone help me out with problem?

Help please?

Do you mean to call Receive Damage event? You can call Receive Damage on the enemy by the Hit Actor reference the same way how it was done with the cast to reference.

Thanks for the response! I’m sorta familiar with the Receive Damage event, which might work for handling damage to the enemy but I still need a way of negating damage to the player when they jump on the enemy.

If you look at my current enemy blueprint, you’ll see that there’s a boolean variable called ‘Null Damage’ that is used to toggle enemy damage collision to the player on/off depending whether the player’s jump collision box is making contact with the enemy. However, due to the jump collision box’s sketchy responsiveness issues I need to find a way of using line tracing to toggle the variable on/off depending on whether the line trace detects the player making contact with the enemy from landing on them from above as a alternative to the jump collision box.

Does anyone know how can be done?

Surely there must be a way of creating a branching condition from the LineTraceByChannel event that I could use to toggle the enemy’s damage collision with the player on & off?

I tried to attach a Branch event to the LineTraceByChannel event but for whatever reason I am unable to directly attach the Branch event to the Break Hit Result event that accompanies the LineTraceByChannel event.

What I am doing wrong & what is the proper way that I can create a branching condition from the line trace?

I’m still kind of new to all , but i think what you need to use is an “Event Dispatcher” HTF do I? Event Dispatchers in Unreal Engine 4 - YouTube

Call it after the hit event, then bind it to all of your enemies

I must have misread the question.

Try attaching your branch condition to the “Return Value” of the line trace. will tell the branch when there is a hit or not. The “break hit” stuff just gives you a bunch of information about what the line is touching.

Thanks for the suggestion, although it probably won’t help with the damage collision toggling issue, but the info should still be useful in other areas.

Thanks again for the help, but how do I communicate the results of the line trace to the enemy blueprint? I need to re-tool the enemy’s blueprint setup in order to take into account the line trace but I have absolutely no idea on how to go about doing .

you can either send an event dispatcher from your pawn to the enemy

or you can create a custom event on the enemy blueprint, then cast to the enemy from your pawn, and then execute the custom event from the pawn blueprint

I did something similar here. I create a custom event on my checkpoint blueprint ( would be your enemy bp)

then on my pawn, i did a line trace, and when the line trace hits something. It triggers the event on my checkpoint:

I’m not sure what I did wrong but it’s not working at all. My character takes damage from landing on the enemy and doesn’t do any damage at all to the enemy.

In addition, I am also getting the following continuously repeating error message:

Player line trace setup:

Enemy jump collision:

I tried searching for “Accessed None trying to read property” but I haven’t been able to come up with anything that would help me figure out what’s causing the error.

Does anyone have any idea on what the source of error is?

where does the “Enemy Ref” node come from? is the problem

Both the custom event references needed a target so I just choice to promote the reference to the enemy blueprint into a variable. I had no idea what the “Current Checkpoint Reference” variable was in your example screenshot, so I just made a blind guess on what it was based on what I thought made sense.

Was it wrong to think that I needed to a reference to enemy blueprint to connected to the custom event references? Or was there something I was supposed to do with the setup of the variable that I missed? If I was wrong then what is the “Current Checkpoint Reference” in your example and what I’m supposed to use as a target for the custom event reference, because I honestly have no idea what I’m doing.

on the line trace node, right click on “out hit” and split the pin, then drag a line from the “Hit Actor” to the target pin of your custom event (where the enemy ref is)

Sorry for taking so long to respond, unfortunately though, things haven’t improved since I last posted. I tried following your advice but for some reason I can’t hook up Out Hit Hit Actor to either of the custom event’s target pins.

What I am doing wrong?

First of all,. For what you’re doing,. You’d probably want a box trace rather than a line trace. Second,. In your first picture you used (“get name ==”) to check the enemy,. Thats not a good way to do it,. You should be casting to your enemy blueprint (you can drag out the cast failed pin and plug itinto another cast if you have more than one enemy blueprint). Or you could use interfaces/dispatchers but let’s keep it simple. I’m a little confused with the rest of the question.

You can’t reference a line trace from a separate blueprint. What you can do,. Is have the enemy do the line trace,. Then in the player have a custom event with an input for an actor variable. Have your linetrace call that event on the player and plug self into the actor pin. Then in the Ayers blueprint,. Drag out the actor pin and cast it to your enemy.

I think that should answer your questonhope it helped!

Do I understand you correct that the reason your own character took damage is because the enemy can cause you damage? And that sometimes the enemy managed to inflict damage on your character before your character did on the enemy?

Is what you want: Your character can only inflict damage from jumping onto the enemy. The enemy can only inflict damage when character runs in form the side? Let me know if is the intended behavior and I will send some example code!

Okay, I put together a small example. Go through it and if anything isn’t clear on how I did it, please let me know and I’ll explain! I know that the code to check if you’re on top of the enemy or not is not the best and should be improved upon. But as a start should do!

Also, you may have to change the engine version to match yours!

Man, it’s taken me way too long to return to subject. Anyways, thanks for going to all the effort that you put into making that sample project but I’ve run into a problem.

The problem being that I don’t know what node is.

339692-event-take-damage.png

Its obviously connected to the “Damage Interface” blueprint interface but that’s all I’ve been able to figure out and I have no idea on how to implement it within the blueprint.