Hi all
I’ve searched the forums and tried a number of codes but have come up dry for this particular problem(s). I am happy with the code for my camera movement, except for the PAN part. If I pan and then try to orbit , the camera snaps back to it’s previous position. It doesn’t do so when I zoom after panning, and it doesn’t do so if I orbit after zooming. So what I need is for the centre of orbit to move from the object on which I was focused to wherever I pan to. The distance doesn’t seem to be an issue.
Secondly, I would like to use a clutch key (eg space bar) plus mouse buttons to control camera movement. This obviously require mouse clicks. Is there a way to disable all other scripts which require mouse clicks while the space bar is pressed? Thanks for all the help.
static var target : Transform;
static var distance;
var panSpeed = 10;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
private var z = 0.0;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Update () {
//Orbit
if (target) {
if (Input.GetKey ("left shift")) {
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, z);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.position = position;
transform.rotation = rotation;
}
//Pan
if (Input.GetKey(KeyCode.Space))
{
transform.Translate(transform.right * -Input.GetAxis("Mouse X") * panSpeed, Space.World);
transform.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
}
//Zoom
if (Input.GetKey(KeyCode.LeftAlt))
{
transform.Translate(transform.forward * -Input.GetAxis("Mouse X") * panSpeed, Space.World);
}
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
[/quote]