Line Trace from a 3d point to mouse location

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 ?

maybe use get hit result under cursor…

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

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)
:large_blue_circle: project 2d mouse location into the world from the camera, hitting that plane (Intersection)
:red_circle: trace from the character’s head towards that Intersection point

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.

4 Likes

This is what I had… :slight_smile:

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

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!

2 Likes