• News

• Industries

• Learning & Support

• Community

• Marketplace

Detect whether actor is off camera

Hi,
I have a 3d game with a static camera and a projectile that can go outside the cameras fov.
I want to detect that and tell the player how far out the projectile is in the event that it has gone offscreen. Counting from the cameras screen bounds.
Ideally I also want to display an arrow on the edge of the screen to tell the player where the projectile is and this is where I’m lost.

I know there’s a function that detects whether actors are being rendered but I don’t know how to detect the cameras screen bounds to properly display the arrow on the very edge of the camera.
Plus I need the screen bounds to accurately calculate the distance of the projectile.
It’s basically a 3d sidescroller.

Hope someone can point me in the right direction.

The way I would start is to use a “convert world space location to screen space” node, which will transform a world space location to 2D coordinates based on the camera location and orientation.

Now, I BELIEVE that this operation has no bounds (i.e. it can report screen space numbers that aren’t ACTUALLY screen space, such as negative values or values greater than the max screen resolution) and, assuming that’s true, what you would do is Get the Viewport Resolution of the player who fired the projectile, check its screen space coordinates against this resolution, and if the value on either axis was greater than the viewport res or less than zero, you would spawn your arrow (widget? IDK how you’re doing it) and set its location to the screen space location of the projectile, clamped to the screen size (maybe offset by the size of the widget, too…)

That won’t solve rotating it, and you may need some additional math driven by the camera distance from the player to calculate the distance accurately, but it’s a start.

Yes that could work.
There is a function: APlayerController::ProjectWorldLocationToScreen that returns a boolean whether it could successfully project the world space to the screen.
So in theory as soon as I spawn the projectile (which will always be spawned within the cameras fov) I could check that and if it returns false I know it’s outside and use simple math(projectedSize - screenSize > 0) on both width and height to check on which bound it exited.

As the camera is static and the projectile travels along a fixed axis I could theoretically also bruteforce the z values for that specific camera position but I would rather have a dynamic solution. If all else fails at least there’s that.

This solution is not complete:

This is the solution:
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“thumb”,“data-tempid”:“temp_193342_1590540214219_362”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

The viewport size returns the X and Y dimensions. if your world position exceeds those dimensions or lower than 0 (top left origin), then it is out of view.
Hook this up to a tick or timer.