# Line Trace from a 3d point to mouse location

**URL:** <https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [June 27, 2021, 5:33am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661 "2021-06-27T05:33:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![3dkobi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@3dkobi](https://forums.unrealengine.com/u/3dkobi)\
**Post date:** [June 27, 2021, 5:33am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/1 "2021-06-27T05:33:12Z")

</div>

I’m making a 3d side-scroller game and I want to do a line trace from the character glasses to wherever I click on the screen with the mouse.

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.

This is the best I could do, but it’s not accurate - When I click roughly in the center of the screen the trace is pretty accurate, but when I click further away from the center it gets less and less accurate…So…What am I doing wrong ?

 ![342541-sharedscreenshot](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/9/d9f01954f009ab22b3808c97c02ee2bc6a9256a2.jpeg)

---

<div class="post-metadata">

**Author:** ![didel23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@didel23](https://forums.unrealengine.com/u/didel23)\
**Post date:** [June 27, 2021, 8:02am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/2 "2021-06-27T08:02:58Z")

</div>

maybe use get hit result under cursor…

also why are you adding 500 units in x and z to already provided mouse location?

---

<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:** [June 27, 2021, 8:13am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/3 "2021-06-27T08:13:46Z")

</div>

> [@3dkobi](#):
>
> So…What am I doing wrong ?

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? 🆒, 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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/d/bd65ce87197e4260352952f46b237c2134855659.jpeg)

🟢 create a virtual plane where the character is and point it towards X (Plane Normal 1,0,0)  
🔵 project 2d mouse location into the world from the camera, hitting that plane (Intersection)  
🔴 trace from the character’s head towards that Intersection point

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/2/52b6467b0fda209047e52e4bf2dd5a7b65cc1a8f.jpeg)

The result for the above.

The line in the anim above should be red…

That’s what I got from the description and intent. Do tell if it’s getting close.

> maybe use get hit result under cursor…

Wouldn’t work if there was nothing under the cursor. And you’d need to play with channels to filter stuff out. Could work well in some scenarios, though - depends on how the world is constructed and how we’re interacting with it, ofc.

---

<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:** [June 27, 2021, 8:39am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/4 "2021-06-27T08:39:49Z")

</div>

This is what I had… 🙂

---

<div class="post-metadata">

**Author:** ![3dkobi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@3dkobi](https://forums.unrealengine.com/u/3dkobi)\
**Post date:** [June 27, 2021, 9:01am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/5 "2021-06-27T09:01:54Z")

</div>

This is exactly what I needed, Thank you very much…

---

<div class="post-metadata">

**Author:** ![jaf518](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jaf518](https://forums.unrealengine.com/u/jaf518)\
**Post date:** [July 6, 2022, 3:45am UTC](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/7 "2022-07-06T03:45:07Z")

</div>

Just wanted to say thanks for this insight! Been trying to solve the problem of 2D mouse aim in a sidescroller for a few hours and this solution was exactly what I was looking for. Plus I learned about the Line Plane Intersection node, which I had never heard of before!
