Download

How do you keep actor within frame? (like starfox)

I’m trying to figure out how they made starfox and I was able to make a rollercoaster type of sim and have the playable character as an actor that moves around left / right / up / down. It uses Get location / set location but unfortunately it glitches easy and the out of bounds which is a given number for now, is easy to pass through.

I’m giving up on this method entirely and before I scratch my brain at it once more, I’d like to ask, how is this made exactly? I’m pretty sure there has to be a better way to bound an actor within the viewport of the cinecam.

You can calculate distance from camera and with the fielf of view calculate opposte side to get max heigh and width: the farther the character from camera, the higher he can go staying within frame. If camera moves than just have another actor for reference.

image
With this the closer the character is to the camera, the smaller will be the area to move.

You can calculate this on character movement, not tick events.

To limit movement, you can try this:
If characterZ > allowed height, then only allow to pass inputs that subtract from that height. So you dont have to add massive colission boxes, it just works by limiting inputs. In a given direction.

Edit: had some time to demo it :rofl:: Ship within camera viewport - YouTube
Changed viewport size just to prove it limits movement within viewport.

Thanks! That makes sense, I will give it a try this weekend :slight_smile:

Added some debug boxes just for kicks :crazy_face::

  1. Debug movable area based on distance to camera - YouTube

  2. Debug update movable area on viewport change - YouTube

lol you seem to be having fun with this! I gave it a try this morning and it worked but I doubt it’s anywhere near as nicely coded as yours. As a bonus I was able to make the ship move side to side, up and down, and holding the trigger buttons lets you move faster on either direction and tilts the ship and it rotates back into position on its own. The biggest issue was that screen resolution was giving my resolution and not viewport. That was the mistake. Next, the pew pews and somehow enemy spawns. Thanks again!

1 Like

I still have the blueprint but it’s a wired mess to share with screenshots lmfao. I prefer you ask if in doubt and I’ll do my best to help.

1 Like

I appreciate you offering advice!

I honestly can’t tell whether or not what I did is working. I have 4 variables XMIN, XMAX, YMIN, YMAX and it has a set value like -120 is XMIN and 120 is XMAX. This was done manually, no in-game calculations.

I tried to make a button that changes resolution to test whether or not it works for more than just resizing the viewport but so far it doesn’t work.

All it does is print the string, doesn’t change anything. But, if the resolution changes, I assume the variables will have to change as well. So -120 / 120 for X might be -240 / 240 if the resolution is double? The bounds are done within the ship’s blueprint using setRelativeLocation so I’m not entirely sure if those values will need to change in the end.

You can have only XMAX variable for horizontal width and *-1 to flip it since it will always be the same but negative or duplicate its value and compare it with the ships X with 120 offset to have 0 < X & X < 240 conditions. Point is either way it can be 1 variable, help keep it clean with less variables and wires around :innocent:.

Screen resolution is not the same as screen size. You should focus on Camera field of view. Resolution will only be a factor if your actual viewport gets affected by the aspect ratio, and this can be covered with the camera’s view angle anyways.

With the camera’s field of view, you’ll always get a fixed width, you can use the aspect ratio (screen height/width = aspect ratio) and get the height (XMax * aspect ratio). Camera view angle will always be the same horizontally regardless of resolution and screen size, the height will change depending on the viewports aspect ratio.

Thanks for the response! Using two variables was what I started out with, didn’t even think much of it lol. The Y is different as it’s something like -90 and 70 but only because the starting position of the ship isn’t centered. But after reading what you wrote, it hit me, that’s dumb. I should start it at center all the time and it’ll make the math easier and constant. Once the ship loads it can be repositioned using setRelativeLocation without the player even noticing.

As for the resolution vs camera angle that is golden information to know. Thank you! I don’t think I’ll have issues moving forward, everything has been answered perfectly.

1 Like