How to aim at the mouse location ignoring depth

One way to do it is via line plane intersection, as seen here:

Essentially, think of it as a virtual plane which you place wherever you want, and then trace from the camera’s location towards the mouse cursor. You hit the plane at the intersection point.

Super useful if there is no geometry, you do not wish to rely on it, you’d rather ignore it or it’s a projection of sort - think VR interface.


Another way is to use collision channels where you decide what the trace works against (visibility by default - hence you’re hitting everything you see). You may only wish to trace against undulating terrain but not the trees, rocks, obstacles and so on.

In which case, you’d assign a dedicated channel to detecting where the mouse cursor is in relation to the ground. Depending on what the end goal is, it might be a preferable and less ham-fisted approach than the above-mentioned line trace intersection.

I want my actor to aim at where the player’s cursor is. It works except for when the player mouses over an object which is closer to the camera than the background (Seen in the clip linked below).

I’ve fiddled with it but haven’t managed to find a solution that worked. Any suggestions would be greatly appreciated.

So the hit result under cursor your using can probably work just fine if you add a new collision trace channel. that will let you allow set the blocks you have there to not block your line trace.

311949-undercursor.gif

Need to add more detail to answer