Hi, I’m making a 2D sidescroller game, and I’m trying to write a script that allows the camera to move in conjunction with the mouse, but only within the bounds. Imagine I have a “target” object in the center of the screen. When I move my mouse above the camera bound, the camera smoothly move to a higher spot, but with a limit.
I currently have the camera follow the mouse movement :
function Update ()
{
transform.position = Input.mousePosition;
}
But I can’t figure out how to restrain the camera movement so that it has a limit to how far it can stretch from a “target”. How can I do this in javascript? Thanks for all the help!