Find and trace edges of viewport/camera frustum

Hello! I’m a bit of a newbie to Unreal so please bear with me - I was hoping you could help with this tricky issue I’m having please.

After a fight sequence is initiated by interacting with an enemy, the camera will pull back and move to give an overview of the surroundings, by focusing on a location that is calculated by getting the midpoint between the furthest enemy AI and the player. The player should then be moved over to the side of the screen to let the two AIs fight. After this is all set up, the camera can be free again. The locations and camera positions will be dynamic so not something I want to set manually.

What I need is a way to create a locked arena based on where the camera is facing after the initial pull back, to stop the player and AIs from moving off screen. So they should be able to move around in the area the camera is looking at, but be blocked by the edges of the viewport.

One thought I had was to spawn in some planes with collision along what would be the edges of the viewport, then do a 360 raytrace around the player and find the closest point from that. But I can’t find a simple way to get the locations to put the planes in. I guess the “camera frustrum” is what I am looking for, but I can’t find how to add collision to that.
This only needs to be set once at the start of the fight based on where the camera starts - after that the camera will unlock, but the arena should remain as it was determined when the camera first set it.

e.g. Image 1: if the player moves this direction, this is fine as we can raytrace to avoid setting a move point beyond the white box object and out of bounds.

Image 2: The problem is if the move point isn’t blocked by an object and goes off screen. Ideally that red line along the bottom should have collision.

What is the best way to go about doing this? If anyone knows a way or can think of any other solution to achieve this same effect, please let me know. Thanks for the help!

Changed title to be more specific to the issue :slight_smile:

I can try and help with the locations relative to the viewport:

Chart laying out the logic:

Debug BP

Result:


Mid locations relative to viewport are not representative of the actualy half way of the edges, so some extra logic is needed to point from corner to corner, get length then * 0.5. Shouldn’t be an issue since we have them in order.

Corners also serve as anchors to rotate them accordingly and adjust scale (length corner to corner).

Hope it helps.


This might help with the AI:

1 Like

Thank you, this worked perfectly.