Hello Ladies and Gentlemen!
I’m in the process of creating game about flying a helicopter in 2d. I’ve already created some pretty nice mechanics, which I’m really proud of. Today, I wanted to add camera follow. I managed to write the script, but it only showed another issues to be resolved.
My question is: what is the best or the quickest way to limit camera and player movement? The more important for me right now is limiting player movement, cuz I’ve found better solution for camera issue - I’ll make it static.
Obviously, I don’t ask for script or sth, just want to know how to do it properly or what should I learn to execute this 
Limiting player movement in what way? And, how are you moving the player — physics, or just moving the transform around directly?
If you’re moving the transform yourself and you just want to keep the player in bounds, then you simply need some “if” tests to see if the new position (when you move) is out of bounds, and if so, move it back in. Something like:
if (newPos.x < minX) newPos.x = minX;
if (newPos.x > maxX) newPos.x = maxX;
It really is that simple in most cases… but you would’ve done that already, so your case must be more complex in some way. Can you explain how?
1 Like
I use physics to move player. It looks like this (sorry, for quality):

My goal is to create constrains around this view, so that player can’t go more than camera purview. Also I consider to destroy object, when it’ll hit constrains.
I’m worried about a lot of issues right now, because I realized that phone screens have different proportions, so it has to be flexible in some way.
Damn…
Maybe, box colliders ?
If you’re using physics to move the player, then the easiest way to constrain that movement is to put big (possibly invisible) boxes around the outside of the screen.
That will reduce the problem to: how do you figure out how to position these boxes just offscreen. You can do that using Camera.ScreenToWorldPoint, but I leave the details to you, because cookies just came out of the oven!
2 Likes
Haha, thank You for reply 
Now, it’s look like this, I didn’t use Camera.ScreenToWorldPoint yet, so I’ve just made temporary solution. I think it will be totally useless, when I will try to run it on phones with different screen size 

I have serious dilemma. I’m afraid that after I use Camera.ScreenToWorldPoint, I would have to arrange all gameObject / sprites by scripts. How professional devs do that ?