MouseOrbit Standard Script modification, help.

Hi everyone,

I am using the MouseOrbit Script to orbit a camera around an object. The object is in the origin (0,0,0).

I have limit the camera movement in the Y axis, so the camera never flies under the floor. I mean, I have put yMinLimit=0

With this restriction we can say that the camera flying area is a semi-sphere.

my problem is that I need to restrict the camera movement more :). I need that the camera flying area would be the half of that semi-sphere. So I have tried to limit the camera movement in the X axis.

I have tried to add xMinLimit and xMaxLimit variables and also call the function ClampAngle(x, xMinLimit, xMaxLimit) but it only works when I move the camera to the “right”. The camera stops when it would fly to the “other” half of the semi-sphere (I hope you can understand my explanation :))

but if I move to the “left”, when the camera reachs to the limit it cross to the other side.

I think that im near to the solution but I need a bit of help. Can anyone help me?

thank you!

igorlean

You should show the actual script in order to get help with it. Also I’m going to move this to the scripting section.

Ok, my modified script is:

function LateUpdate () {
if (target Input.GetMouseButton(0)) {
x += Input.GetAxis(“Mouse X”) * xSpeed * 0.02;
y -= Input.GetAxis(“Mouse Y”) * ySpeed * 0.02;

y = ClampAngle(y, yMinLimit, yMaxLimit);
x = ClampAngle(x, xMinLimit, xMaxLimit);

var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.position = position;
transform.rotation = rotation;
}
}

I don´t touch the ClampAngle function nor the Start function.
I declare the xMinLimit and xMaxLimit variables exact like the yMinLimit and yMaxLimit variables.

thanks!