Line trace, hit by the direction from my ThirdPersonCharacter

Hello, I am quite new to unreal engine 5.
Currently I wanted to start the combat system with my 2D third person character. The problem is that the line trace “hits” from the direction from the camera. I want the line trace to hit out of my character.

Thanks for your attention and have a good day

1 Like

What is start attack? Just a scene component attached to the player’s something? To what, specifically?

You’re asking for a socket location without specifying which one - is this intentional? If you’re not using sockets, it might be more straightforward to:

image

Same result (afair), but skips the socket look up.

image

The Left arrow is the Start attack socket, and the right one is the end attack.
thats basically the hit-range

Thank you for your answer btw!

Since you’re drawing debug trace, can we see it? Essentially, there’s nothing wrong with what we see - the issue must be then where we cannot see. How is the character hierarchy set up?

I would love to show a video, but i cannot send it here so i try to explain.

image

Here is a screenshot of my character when im pressing the hit button. The Line trace is facing into the direction of the camera and not the direction of my character.

When my character is facing down, the line trace is still going to the direction of the camera. I have the Paper ZD and 2D plugin if that helps. I have made it so that depending on the direction the character looks, the animation is also played to the direction. And I would like to do the same with the attack system, so that the character hits where he looks.

Thank you!

image

Here is the image where he faces down but the hits goes not at the direction, hes facing.

Could we please see the component hierarchy of the character? What are the arrows attached to? You can also make the arrows not hide so you can observe their position at run-time - perhaps this will quickly explain what is going on. This is crucial since you’re using their position for tracing.

I have the Paper ZD and 2D plugin if that helps.

Sadly, I’m not too familiar with those. But tracing is straightforward A->B. I wouldn’t blame tracing itself, but rather the components’ locations instead. And / or the way the rotation is set up.

image

I dont know if you can see that very well but there are the two arrows. they are facing at the direction of the camera. I will have to do more answers so i can send more screenshots.

Here is the viewport from the Character

Here is the event graph (dont mind the “Is attacking set” boolean)
The start attack is the first arrow that comes out of my character. The end Attack is the Last one.

Edit: Thats it. I dont know what i can show anymore except this. That is the only logic behind the Attack system/Line trace.

I am a bit baffled as I do not fully understand what the expectations are; with both arrows attached to the capsule:

The trace would go from root of one arrow to the root of another. When you unhide the comps:

And then run around, are you getting a different result? The trace does not go from arrow to arrow? (yellow, below):

The trace is going from arrow to arrow but as i said, the line trace is not looking at the direction of the character. When the character looks down the trace should go down too. Its basically set to the camera direction. Thats what im planning to do. My expectations were not that it would work directly, but I wanted to know how it would work, that is, how I could manage to do it. So don’t take it the wrong way.

Thanks a lot!

As you can see, the trace is still up so at the direction of the camera. But my Character is looking in a nother way, my plan is, that the trace is looking at the same way, where my character is facing.

The arrows are attached to the capsule - they follow capsule rotation. Attach them to another component whose rotation / location you wish them to follow.

When the character looks down the trace should go down too.

If by character looking down you mean the camera direction, you could use that for tracing instead.


How are you rotating the character? What are you actually rotating for directional changes?

Since it should be a 2D game with 3D background i changed the rotation a bit:

Before “Add Controller Pitch input” there is the node “Enhanced Input Action IA_Look”
It couldnt fit in the screenshot. I also changed the movement a bit so it feels like a 2D game.

In the anim you had posted, the only place where I can see the trace going off is here:

Below, the arrows follow capsule rotation as you clamp turning:

And should trace as red indicates. Are you expecting the trace to follow green because we see the sprite from the side?

Gents, not to add noise to the conversation but I always thought that the line trace nodes required a directional vector for the “end”. Both of your examples use a world location instead. Does that work as you expect? I would expect to see the following:

For line trace start

StartAttack->GetWorldLocation

For line trace end

StartAttack->GetWorldLocation + StartAttack->GetWorldRotation->GetForwardVector X scalar distance, let’s say 100

Something like this for the end

Could this be the problem? Or at least part of the problem?

1 Like

OP wants to trace from A → B, using arrow comps as points for this, instead of direction (I’m ignoring the sockets here, does not seem relevant). In their case, it does not matter where the arrows are pointing, only where they are. And since they are attached to the capsule the way they are, things accidentally line up anyway.

Does that work as you expect?

Yup, why wouldn’t it? Nothing stops you from:

image

Understood. I don’t have the editor in front of me so I couldn’t test. Just not how I’m used to seeing it. Thanks for the clarification.

As you were!!

1 Like