2D camera restriction(still need help)

in my 2D shooter(Orthographic view) i want the camera’s position to be locked within a certain area, i used this code from someone else which seem to work for em but whenever i reach those restrictions the players tries to force his way out the those restrictions making the camera shake since its attached to the player.

function Update () {
	transform.position.x = Mathf.Clamp(transform.position.x, -49, 49);
	transform.position.y = Mathf.Clamp(transform.position.y, -49, 49);
}

any help plz?

EDIT with 2nd problem:
once u get to the extreme sides then the camera will not let u go back in the middle of the screen, also another fix for my previous problem is u can just use LateUpdate :confused:
rly dunno where to start to fix this one…

I am not trying to be smart to you, but check this script reference first:
http://unity3d.com/support/documentation/ScriptReference/Mathf.Clamp.html

That explains how Mathf.Clamp works or what it does.

Explained in plain english, it takes minimum and maximum value and makes sure that the value you supply stays (clamps) within the range.

so I cant fix the Update function unless you tell more about how your script works. Show us some more code or explain why you think this script should work. I have a hard time understanding how it could this way.

umm, figured it out, i had the code in a separate script and put it on my character as well, what happened is the line

transform.position.x = Mathf.Clamp(transform.position.x, -49, 49);

was happening BEFORE this in the Update which made look like it was shaking

transform.Translate(Vector3(xMove,0,0));

so basically it was like saying move over there, wait! come back this area is off limit so come back over and over; classic mistake, but couldnt have known :stuck_out_tongue: