# Line tracing in screen space

**URL:** <https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581>\
**Category:** Blueprint\
**Tags:** Raycast, screen-space, unreal-engine, Physics, Blueprint, question\
**Created:** [March 21, 2023, 10:58am UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581 "2023-03-21T10:58:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asterix\_Us](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/asterix_us/32/549400_2.png) [@Asterix\_Us](https://forums.unrealengine.com/u/Asterix_Us)\
**Post date:** [March 21, 2023, 10:58am UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/1 "2023-03-21T10:58:26Z")

</div>

Hi! I’m trying to implement an aiming system similar to the one in Weird West (link to provide a more visual example: [The Aiming System That Broke Weird West - YouTube](https://www.youtube.com/watch?v=mf2gyaXd4LA), 5:59)

The problem I’m having is that I can’t figure out a way to aim in 2D, like they explain in the video:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/4/324a6ef83d4abc0481316808379a628665d828d3.jpeg)  
For instance in this example, the result _should_ be a hit but it’s not. My idea so far is to get the player’s position in screen space, get the mouse position (same but is in screen space already) and the do a cast from there, but it doesn’t work properly.

Does anyone have a better idea on how this is done? 🥲

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 21, 2023, 11:17am UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/2 "2023-03-21T11:17:38Z")

</div>

Isn’t this 3D?

---

<div class="post-metadata">

**Author:** ![Asterix\_Us](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/asterix_us/32/549400_2.png) [@Asterix\_Us](https://forums.unrealengine.com/u/Asterix_Us)\
**Post date:** [March 21, 2023, 11:22am UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/4 "2023-03-21T11:22:34Z")

</div>

The game is in 3D, yes, but the line trace I want to make I imagine should be in screen space

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 21, 2023, 11:34am UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/5 "2023-03-21T11:34:06Z")

</div>

Ok, me being thick, but I don’t get why. Because it’s actually in game space.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 21, 2023, 2:25pm UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/6 "2023-03-21T14:25:29Z")

</div>

> [@Asterix\_Us](#):
>
> The game is in 3D, yes, but the line trace I want to make I imagine should be in screen space

UE does not really have good tools for doing something like that, afaik. I mean, the venerable HUD class can put up world deprojected UI hit boxes up. You’d then need to write a line intersection code.

* * *

Instead, would something like this work for you:

🟢 stuff we detected  
🟣 stuff we can actually see and hit from the character’s viewpoint

The height and distance to targets does not matter, neither does geometry for aiming. Do tell if you think it could work so I’ll clean it up and post it.

---

<div class="post-metadata">

**Author:** ![Asterix\_Us](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/asterix_us/32/549400_2.png) [@Asterix\_Us](https://forums.unrealengine.com/u/Asterix_Us)\
**Post date:** [March 21, 2023, 3:42pm UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/7 "2023-03-21T15:42:36Z")

</div>

Hmm this looks very interesting! How is it made? 😱 I would love to try it out and see it if fits

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 21, 2023, 4:13pm UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/8 "2023-03-21T16:13:28Z")

</div>

- long screenshot is long:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/d/7ed74983e1acbd65443ce28b6e21a5ae7337d025.jpeg)

yeah, no. Forums do not like high res pics:

> **[mbloslpi.png](https://drive.google.com/file/d/12oW9oPq4OvhnSQWubRmrCA3bVlzjGzzL/view?usp=share_link)**
>
> Google Drive file.

- script:

> **[multi box Line Plane Intersection LoS aiming thingamabob | Unreal engine Code...](https://dev.epicgames.com/community/snippets/oRA/unreal-engine-z-independent-multi-box-line-plane-intersection-aiming-thingamabob)**
>
> Multibox oriented trace fetching LoS targets.

- project

> **[multiBoxLinePlaneIntersection.zip](https://drive.google.com/file/d/1QpplZEZ_0_7mLU1cuxOYVji2W4A2qTVM/view?usp=share_link)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![Asterix\_Us](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/asterix_us/32/549400_2.png) [@Asterix\_Us](https://forums.unrealengine.com/u/Asterix_Us)\
**Post date:** [March 21, 2023, 4:34pm UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/9 "2023-03-21T16:34:53Z")

</div>

It’s very very useful, thank you! The only thing that I think will probably be ideal and I’ll experiment with it, is to rotate the plane so that it’s side is always facing the camera, basically being like a big plane-knife cutting the world and testing for traces.  
So it looks like a 2D line from the pov of the player, but it’s actually a rectangle.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 21, 2023, 4:40pm UTC](https://forums.unrealengine.com/t/line-tracing-in-screen-space/795581/10 "2023-03-21T16:40:45Z")

</div>

If you mean the Line Plane Intersection, then yeah - it’s a super versatile approach:

> [@Line Trace from a 3d point to mouse location](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/3):
>
> You’re tracing with a fixed distance of 500, replacing the projection’s X with a fixed value. It’s actually hard to imagine how that would look like, a strangely distorted / twisted undulating surface mayhaps? cool, for sure. I want this trace to stay on the same plane as my character, so the X value of the start point & end point should be the same. Consider the following: green_circle create a virtual plane where the character is and point it towards X (Plane Normal 1,0,0) …

If you feed it camera forward as normal, it’d be a bit like tracing against the inside of a sphere. But I’m not sure I’m fully grasping what you’re after.

Do tell how it goes.

Good luck!
