Find an offset position in front of camera along a ground plane

How would do you place an object, with a given offset, on a ground plane in front of the camera. Example, you are walking and trigger a sign to pop up 1m in front and 1m to the right or the camera. Regardless of if the camera is rotated to look up or down.

This only works if you can prevent the camera from pitching all the way up or down.

Copy the camera’s forward vector, zero the y, normalize to get a forward vector in the XZ plane. Scale by distance to get an offset directly in front.

Create a right vector from the forward vector using the 2d “swap and negate” trick: if forward is (x,z), right is (-forward.z, forward.x). (Graph that to make sure) Scale by distance to get an offset directly to the right.

Add them together to get the offset. Add the offset to the camera position to get the location.

Games typically place objects in the world permanently and just show/hide them based on collision or proximity.

1 Like

Thanks for the quick reply. This is similar to what I was trying, but my results were still off. I’ll give this a try.
edit: I was forgetting to zero out the y on the forward direction. That was the issue. Thanks again.