Line Trace from screen center to world

Hey everybody,
I’m currently doing a small amateur FPS game and I’m doing right now firing system and I would like to trace from my crosshair (Which is in the center of my screen) to the world.

I tried to use the “Convert Mouse Location to World Space” function but it doesn’t work, my linetrace isn’t on my crosshair.

Here is my current script for line trace :

1 Like

Just a second. I will open up a project to show it to you.

Will post an answer then.

Thank you for your answer dude !

It’s almost that !
But look, when I look at the floor, my line trace begin to shift to the bottom, like this :

Yeah, it works guy !
As you said, it comes from the Z value.

Thank you guy really !

Get the camera’s location and rotation like so;

5000 is the distance it fires the trace. You can set it to any distance you like.

Here, this should work.

I commented it for you:

Picture link: http://puu.sh/c1wg1/58a0679039.png

2 Likes

I guess that’s because the Z value you add is too low.

Look in the components tab at what height your camera is and use this for the Z value instead of “Base Eye Height”.

Np, would you accept the answer on the left side of the answer with the check mark? So others will see that this question was solved.

This is what you really want.

6 Likes

I suppose this should be the accepted answer. Clean, short, simple and does exactly what you need for aiming.

Thanks, how about an upvote instead?

4 years ago I was still learning. (: while all answers work, this one here is indeed the better one. I changed the accepted answer. Cheers!

Unreal 5 there is no Get camera location from the FPS project.
Could you remake the example again?

Drag camera component, get its forward vector, get component location in world.