• News
• About

• Industries

• Learning & Support

• Community

• Marketplace

Download # [4.17.2] An Engine function for ending a trace at a specific Z height rather than a trace length?

Below is an image to illustrate what Im looking for.

The goal is to create a beam effect that starts at the left most dot, stays level with that dots Z Height, but ends the beam at the intersecting point with the Trace line.
Currently I send a trace from the camera to the floor. And just manually change the .Z portion of the resulting ImpactPoint FVector which results in the beam being equivalent to line C.
I want the beam to be equivalent to line C + D.

Is there an engine function that can do this?
If not what would be the best way to accomplish this?

So you know where C starts, where the camera is and in what direction it is pointing? In that case you can calculate the distance between the camera and the intersection with D with a bit of math:

a = Camera.Z - C.Z (aka vertical distance between C and the camera)
alpha = angle of the camera to the Z axis
cos(alpha) = a / d
=> d = a / cos(alpha)

When you have the distance d you can multiply it with the forward vector of the camera and add the camera location to get the world position of the intersection.