Hello,
I’m creating camera controls for a 3D RTS game. The camera can zoom, rotate, and move in any direction. I’m trying to find a good way to “zone” camera movement.
Summary
I tried two ways of organizing camera movement: Rigidbody.AddForce and transform.Translate.
Movement works fine for both. Zoom and rotation also work well, but limiting camera movement is a problem.
AddForce allows me to use Colliders and Rigidbody for this, but it adds velocity and all the physics stuff that I don’t want to handle.
Translate is also good, but the only thing that comes to mind in this case is using some hardcoded coordinate checks. This works well with a non-rotatable camera, but poorly if I want to rotate the camera (because the camera axis rotates).
Can someone recommend a guide? Maybe there is an easier way to do all this? I have a feeling that I’m reinventing the wheel and missing something, but so far I haven’t found any good examples solving this.
Thanks!
P.S.
Objects related to the camera look like this:

Summary
- [rotation point] has “Camera Control” and “Rotation” scripts. It is moved, and [Camera_Sphere] is rotated around it.
- [Camera_Sphere] is an empty object with [Main Camera] attached to it.
- [Main Camera] is the camera and is rotated 45 degrees on the X axis.
- [CameraPositionGlobal] is an empty object that I wanted to use as a sort of mimic of the rotation point object, but with no rotation applied to it. The idea was to control that the camera is not leaving the restricted zone using it.
Function that handles rotation look like this:
void check_position()
{
//x and z are speed applied to X or Z axis of "rotation point"
x_loc = (int)Math.Ceiling(x * 100.0f);
z_loc = (int)Math.Ceiling(z * 100.0f);
//"rotation point" position data
Vector3 global_pos = Rt.transform.position;
//"CameraPositionGlobal"
TestObj.transform.position = global_pos;
/*main idea here is to stop and dont allow movement in specific direction if we reach border*/
//trepassing the z = 0 axis
if ((int)TestObj.transform.position.x <= (int)min_x && x_loc < 0)
{
x = 0.0f;
flag_z = true;
}
else
{
flag_z = false;
}
//trepassing the x = 0 axis
if ((int)TestObj.transform.position.z <= (int)min_z && z_loc < 0)
{
z = 0.0f;
flag_x = true;
}
else
{
flag_x = false;
}
//trepassing the z = 100 axis
if ((int)TestObj.transform.position.z >= (int)max_z && z_loc > 0)
{
z = 0.0f;
flag_z2 = true;
}
else
{
flag_z2 = false;
}
//trepassing the x = 100 axis
if ((int)TestObj.transform.position.x >= (int)max_x && x_loc > 0)
{
x = 0.0f;
flag_x2 = true;
}
else
{
flag_x2 = false;
}
}
Other code is basically just a bunch of transform.Translate calls in different directions based on mouse position/keys pressed. I was not allowed to attach files because I’m a new user ![]()