Using ViewportToWorldPoint to bound player


I am developing a sidescroller game in a similar vain to space shooter such as R-Type for a uni project. I am now working on the camera for the game. I have the camera scrolling and now need to bound the player so they cannot move off screen.

I needed help with this as I am not to sure how to stop the player moving off screen. I have used mathf.clamp to stop them on a stationary screen, but how do I stop them when the screen is always scrolling?

Any help is greatly appreciated, thanks :slight_smile:

Can you keep the camera stationary and move everything else but the player? (Parenting everything you want to move to an empty GameObject will make it easy.)