Do a line trace in character facing direction (Blueprint Sidescroller)?

I’m trying to do a line trace in the direction the character is facing. This works fine as long as the character is facing right but I can’t figure out how to determine that the player has turned and is now facing left in order to invert the line trace.
I tried the forward vector (which gives me a trace to the origin of the world), broke down the transform’s scale to access the y component, tried character rotation… no luck.

Any ideas how I can get the the direction the character is facing?

I finally got it working! :smiley: I gave my character an additional socket (on the floor between the feet) and used its rotation to find the end point of the trace while the start remained the actor location.

I still feel like this should be possible by just using the pawn’s rotation but at least it’s working now.
Thanks everyone for suggestions! And - awesome work with those additional nodes, they will surely come in handy! :slight_smile:

“And - awesome work with those additional nodes, they will surely come in handy! :)”

Hee hee, thanks!

Can you try this setup: NOTE: Instead of Muzzle Flash Light use your character.

1 Like

Gah you just beat me, I was about to say I typically use the pawns normalized rotation.

Thanks but with that setup I still get a trace that starts at the character, reaching “into” the world still in view direction of the sidescrolling camera.

Here are both my blueprint and what I get in PIE.

It could be because the capsule component doesnt actually rotate. You might want to try setting the location to scene component or the pawn itself.

I added a little debug printout to see the rotation values and judging by that neither the capsule nor the pawn actually rotate.
The GetWorldLocation doesn’t work with the pawn but there’s not difference in the outcome whether I use the mesh component or the capsule.

I did the line trace in a first person example earlier and it works fine so this almost seems like a bug…?

Are you basing it on one of the sidescroller exmples? Perhaps theres something to that, maybe a bug yeah.

Yep, it’s the Blueprint Side Scroller.

Yeah you cant select the pawn itself, it thinks its a CapsuleComponent when I try to get self. It must be how the template is written, it doesnt look like its possible to make the mesh the root component and the capsule a child.

Dear Mario,

You are using Control Rotation,

That is the direction of the Camera, the player controller, not the pawn.

In first person that works because the pawn is always facing the same direction as the camera/player controller.


#GetActorRotation()

Use GetActorRotation() in your pawn blueprint and that should fix everything :slight_smile:

Thanks for the reply but it still doesn’t work :frowning:
This is what I have now:

I’m using the Print String at the end to see if there’s any difference in the rotation whether my character is facing left or right - but there isn’t.
I’m probably missing something really simple but I just can’t see what…

I think you want absolute world space direction, not relative

the easiest way to do a trace is this (for others reading this in the future):

#Start = Actor Location

#End = start point + TraceLength * Direction

And Direction is world space direction, and is the rotator made into a vector.

You just need to convert the world space rotation of your pawn into a vector.

I have a node to do this in my BP nodes library
http://forums.epicgames.com/threads/977316-(35)-s-Blueprint-Nodes-Plugin-For-You!-Float-as-Str-w-Precision-Ragdoll-Traces

conversions.jpg

So once you have that node (my plugin is less than 10mb and does not require any code compile)

you just do this

  • Start = Actor Location
  • Direction = Actor Rotation as a Vector
  • Trace distance = your chosen distance

Then the trace will always follow the rotation of the actor, moving forward TraceLength amount

#Summary

You have all of the blueprint correct except the Rotator as XVector part

you need Rotator as Vector, which is what my Blueprint node gives you.

PS: In my BP library I also have traceinfo nodes to make doing traces from a weapon socket or from the character mesh even easier:

http://forums.epicgames.com/threads/977316-(35)-s-Blueprint-Nodes-Plugin-For-You!-Float-as-Str-w-Precision-Ragdoll-Traces

Still not working, even with your new nodes. The trace when you press K goes from my character to the world origin and the one when you press J goes “into the screen”.

I put my project on the Rocket dropbox (Marquardt/MyProject.zip). If you have the time I’d appreciate it if you (or anyone else) could have a look at it. Starting to feel a bit stupid for not getting this to work :confused:

The only way i got it to work was with sockets. This is what i did

I know this is from a long time ago but whoever gets here and is working with paper2D in 2 dimensions, insted of puting a socket, you can pick the sprite component of the actor and use the “get Socket Transform” function as in this example.

Anyway, much appreciated help, that put me on the correct track.

Hello,

This is a question from the beta version of the engine. We are marking this answered for tracking purposes. If you are experiencing an issue similar to this please post a new question.

Thank you.