Keep Player within moving & rotating camera in Unity 3D

Very Simple Question: How do I keep my Player within the Cameras boundary?

My player is the camera’s child which is following a Dolly Track and I can move the player freely in the cameras current X and Y axis, but I can move even outside the camera view while it’s moving along the dolly track, which is something I don’t want.

I don’t want to set long cubes as invisible barrier because the “no friction” physics material still has some friction when the player flies agains/along the cubes.

I tried the tutorial from the yt channel Press Start “Unity - Keep The Player Within Screen Boundaries” but sadly this works only on not moving cameras, or as I assume, on cameras that are at least not rotating :confused:

I just want the cameras boundaries to stay as the cameras boundaries no matter how the camera is rotated



Usually the simplest solution is to just kill the player when they go offscreen.

This can be improved upon by flashing a warning to the user saying “Catch up or DIE!” or something like that.

If you INSIST on moving the player when the camera moves to force the game along, then you need to have some method of the camera telling the player which way to move when the player gets too near the edge. This might be as simple as raycasting the center of the screen into the world and telling the player to move that direction.

This also means game design questions like “What happens to the player if he’s snagged behind a wall and forced to move?” Teleport? Death? Snap?

I’ve got the movement already and it is flying with the moving camera just as I want, I just want the player to not be able to leave the cameras view when I keep going left, right, up or down. I only know that this has to be done with something like the cameras screen width and height just like in this tutorial video from above,

Hmmm It’s a little hard for me to describe this problem… you can search on youtube for “gummi ship kingdom hearts 2.5” this is what I want to kinda remake. I’ve got the same movement just like this game, all I need now is a barrier or boundaries for the player/rocket to not fly out of the camera bounds

Looks like the camera is just parented to the player, or perhaps vice-versa.

See how the player regularly makes zero movement? They’re just moving either one of them relative.

Probably Camera is on a track, player is a child of the camera, and player controls only allow movement within a local bounds that will always be within camera view.

And I made it to this point right here, the bounds. I want to know how to archive this.

I need to understand how the bounds were made.

If the parenting distance is fixed, they probably just hard-wired it… like say allow X to go from -5 to +5 and allow Y to go from -4 to +4

Since you are parented to the camera, AND you are updating .localPosition (not .position!), it should just work.

Actually, it DOES just work. See enclosed fully-functional package. Enjoy!

8409153--1111014--Screenshot-mw4-133065495374070240.png

8409153–1111017–CyberiaLivesAgain.unitypackage (341 KB)