I’ve read the documentation for the Camera, but still don’t understand. The 3 tutorials I’ve followed, including [this one](http://this one), have the player at the center of the screen when the camera catches up. I want to code the camera like this:
The player can move anywhere on screen with no gravity (Completed). If the player goes very close to the right wall, the camera slowly “unlocks” more right screen. The left of the screen does not do this; If the player moves all the way left, he hits a wall. Once the player and camera move right, there’s no accessing the old screen to the left.
The closest example I can think of for the camera is like a 2d runner game, but the player can move anywhere on screen without gravity. I wouldn’t ask someone to code this unless they wanted, so if there are any references or tutorials you could link I would greatly appreciate it.
I don’t know of a tutorial. But you can do this yourself, step by step.
- Make an empty CameraController script, and attach it to your camera. Make sure that runs (though it does nothing).
- In its Update method, write some code to figure out where the player is on screen. You could do this using Camera.WorldToScreenPoint, for example. Your script will need a reference to the player transform. When you’ve calculated the screen position of the player, simply Debug.Log it. Run and confirm that those log messages are what you expect.
- Now add an “if” statement so that it logs only when the player is close to the right side of the screen (however you define “close”). Run and test.
- Now, inside that if statement, shift the camera’s own transform to the right slowly. Something like transform.position += 0.5 * Time.deltaTime might do. Run and test.
- Refine that motion until it feels just right.
If you have trouble with any of these steps, post here and get some help. Good luck!
1 Like
@JoeStrout Thank you so much! I will give it a go!
1 Like
@JoeStrout , hi, I just wanted to say that your advice did help, and I was able to make it work!
1 Like