- Home /
Help with a 2d camera Controller
I need to help with my 2d camera controller, every attempt I make at one has failed miserably, I need a 2d camera controller that is like Mario, is will follow the player the the x axis/left and right forever, but on the y axis/up and down, I don't want it to go down below a specific point, but if the player gets close to going above the view, the camera will move up to follow the player. If you have any questions feel free to ask me! I REALLY NEED the help!
Answer by Firedan1176 · Aug 09, 2018 at 02:25 AM
You can take control of the y axis by implementing Mathf.Clamp([value], [min], [max])
. For example, if you wanted the camera to always stay above the y axis, you could do something like this:
Vector3 pos = Camera.main.transform.position;
pos.y = Mathf.Clamp(pos.y, 0, 100) //The camera's y will clamp between 0 and 100
Camera.main.transform.position = pos;
@Firedan1176 Ok, Thank you, I'm a noob so can you please show me how I would write that in my code, such as what would need to be the update loop and so on?