- Home /
Camera scrolling?
i am making a 2d platformer mario type game and a need a camera scrolling script. I've been following the 2d platformer tutorial but their camera scrolling script won't work & has errors. Could someone please help me out to make a camera controlling script?please!? thanks for the help!
Answer by noradninja · Aug 20, 2010 at 02:06 AM
All you need to do to make the camera follow the character in 2D is this:
Take your Main Camera and position it at a 90 degree angle to your character (so youre looking at the side view of your player). With the Main Camera hilighted in the Hierarchy view, look in the Inspector View and make sure Projection is set to Orthographic to get a truly 2D look and feel. This is all you need to do to get this type of view.
Now, to get the camera to scroll along with your character as he/she/it moves, just position the camera the distance you want it from your player (so they are the size you want), and in the Hierarchy View, drag the Main Camera object on top of your player, making the camera a child object to your player. Now, when your player moves, because the camera is a child of the player, your camera will move with it, always keeping the player centered in view and the world will appear to 'scroll' around the player. This is how the camera works in Super Mario Brothers 3 and up, all the Sonic the Hedgehog games, etc. Easy to do, no scripting required :)
Also, when you ask questions, be more specific. What do you mean by the script 'won't work and has errors'? Tell us the exact errors (copy and paste them from the console in Unity). Post the code of the script (including any modifications you may have made). We can't read minds, and not having this info will completely ruin any chance you have in us helping figure out what is going wrong for you.