Get hit result under cursor - trace end equal to 0,0,0 when no blocking hit

When the player clicks on open space…


You know:

  • World Location
  • World Direction
  • Desired End Z (height) (probably character gun height)

Let’s do some math to find to find that EndPoint.

  • We can find the height difference by subtracting Current Camera Height Z with Gun World Location Z
  • We can find the X difference with Trigonometry
  • We can find the Y difference with Trigonometry

Here’s how the X would be found.

And here’s how I would implement the whole thing in BP

You can grab a copy of this code [HERE][5].

If my answer was the solution you were looking for, could you upvote / mark as answer?

So I’m trying to get a third person character to shoot at the cursor’s location whenever it is locked onto an enemy.
I’m using Get Hit Result Under Cursor and the node works as intended when the result is a blocking hit.

However, if it does not hit anything (which is what happens whenever the cursor is over the sky), then the location vector is equal to 0,0,0 and the bullet won’t shoot at the right location.

So what I thought about doing was using Trace End instead of Hit Location, but if there is no hit, Trace End is also equal to 0,0,0.

I don’t really know whether this is a bug or not but it seems weird that Trace End is at 0,0,0.
It’s also worth noting that I did change the trace response in the Sky Sphere mesh in BP_Sky_Sphere to block the trace but it still returns false when I check if there was a Blocking Hit.

In any case I was wondering if there is a workaround for that beside add extra volumes to block the traces.

Seems to work for me. Deproject Mouse Position to World will return a proper vector even without a collision trace under the cursor. One thing to watch out for is that the length of the returned vector is inconsistent.

This method will get the location at a given height if it hits the void.