# Line Trace from screen center to world

**URL:** <https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399>\
**Category:** Community & Industry Discussion\
**Tags:** Trace, line, unreal-engine, screen, question\
**Created:** [October 6, 2014, 11:23am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399 "2014-10-06T11:23:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MAlexD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MAlexD](https://forums.unrealengine.com/u/MAlexD)\
**Post date:** [October 6, 2014, 11:23am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/1 "2014-10-06T11:23:45Z")

</div>

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 :

 ![17117-linetrace.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/4/a24ba2fcc9f90cd680f06f508a9722ac8aaae1b0.jpeg)

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [October 6, 2014, 11:28am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/2 "2014-10-06T11:28:42Z")

</div>

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

Will post an answer then.

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [October 6, 2014, 11:38am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/3 "2014-10-06T11:38:26Z")

</div>

Here, this should work.

I commented it for you:

Picture link: [http://puu.sh/c1wg1/58a0679039.png](http://puu.sh/c1wg1/58a0679039.png)

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/5/55af80799ded0e95f0d50dbafbaefa686b646241.png)

---

<div class="post-metadata">

**Author:** ![MAlexD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MAlexD](https://forums.unrealengine.com/u/MAlexD)\
**Post date:** [October 6, 2014, 11:58am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/4 "2014-10-06T11:58:25Z")

</div>

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 :

 ![17119-linetrace2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/1/481f698598f542604b564c4ac7141c3216da0c4c.jpeg)

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [October 6, 2014, 12:02pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/5 "2014-10-06T12:02:24Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![MAlexD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MAlexD](https://forums.unrealengine.com/u/MAlexD)\
**Post date:** [October 6, 2014, 12:15pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/6 "2014-10-06T12:15:10Z")

</div>

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

Thank you guy really !

---

<div class="post-metadata">

**Author:** ![Jacky](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jacky/32/918690_2.png) [@Jacky](https://forums.unrealengine.com/u/Jacky)\
**Post date:** [October 6, 2014, 12:16pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/7 "2014-10-06T12:16:54Z")

</div>

Get the camera’s location and rotation like so;

 ![17120-linetrace.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/8/8a882e3e30d35485b572906063df8ba0dcd7f59e.jpeg)

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

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [October 6, 2014, 12:39pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/8 "2014-10-06T12:39:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zectbumo54](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zectbumo54](https://forums.unrealengine.com/u/Zectbumo54)\
**Post date:** [July 10, 2018, 2:10pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/9 "2018-07-10T14:10:16Z")

</div>

![246881-blueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/0/af0fec399abd74c5dbf201665ad7e3c4c7e5c564.png)

This is what you really want.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c4b0b854](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c4b0b854](https://forums.unrealengine.com/u/anonymous_user_c4b0b854)\
**Post date:** [December 24, 2018, 7:37pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/10 "2018-12-24T19:37:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zectbumo54](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zectbumo54](https://forums.unrealengine.com/u/Zectbumo54)\
**Post date:** [December 25, 2018, 2:20am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/11 "2018-12-25T02:20:50Z")

</div>

Thanks, how about an upvote instead?

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [December 26, 2018, 12:18am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/12 "2018-12-26T00:18:17Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![SharkPolo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SharkPolo](https://forums.unrealengine.com/u/SharkPolo)\
**Post date:** [February 19, 2023, 11:49pm UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/13 "2023-02-19T23:49:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [February 20, 2023, 6:38am UTC](https://forums.unrealengine.com/t/line-trace-from-screen-center-to-world/295399/14 "2023-02-20T06:38:28Z")

</div>

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