- Home /
need help with camera
first of all im quite beginner at this.
okay so the problem is this:
im trying to make 2d game, 2 players, both at the end of the platform shooting each other with cannons. the idea is to have a camera i can move in this field by holding down right mousebutton.
been viewing the lerpz code for the base of the game (camera scrolling and so on) and i made and invisible cube object to "move" the camera.
i attached and self-written fairly easy (too easy?) piece of code to move my invisible cube wich simply uses transform.translate to move my cube while getmousebutton1 is true (i'd paste the code but i just modified it after a small break in on the project and i can't remember the original code how dumb of me)
with that code the invisible cube just keeps going and going if you move your mouse over the level borders, the camera stays inside the borders but the "camera control cube" just keeps going farther and farther away.
any idea how to get the cube stay inside level boundaries?
at the moment im using camera scrolling and focus for my camera and level attributes script for my platform from lerpz tutorial.
Answer by Tommy · Apr 28, 2011 at 09:23 AM
Im not quite sure, but this might get ju started atleast:
var maxValue = 0; var minValue = 0;
function Update () { if (transform.position.x >= maxValue) { transform.position.x = maxValue; } else if (transform.position.x <= minValue) { transform.position.x = minValue; } }
Also, change the maxValue and minValue to whatever suits.