Does some one have a zooming script?

Can someone tell me how to do a zoom in zoom out script?

4 Answers

4

Two common ways of implementing zoom are to modify the field of view for perspective projection (decrease to zoom in, increase to zoom out) or orthographic height for orthographic projection (similar), or to move the camera forward or backward along its forward axis.

Which method to use depends on what type of camera you're implementing and what sort of behavior you want. If you need more help than that, perhaps you could clarify your question (specifically what type of behavior you're looking for, and what aspect of the implementation you need help with).

A modified MouseOrbit (from the Standard Assets) script. Move the camera forward or backward along its forward axis by the mouse scrollwheel:

var target : Transform;
var distance = 10.0;

var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = -20;
var yMaxLimit = 80;

private var x = 0.0;
private var y = 0.0;

@script AddComponentMenu("Camera-Control/Mouse Orbit")

function Start () {
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;

    // Make the rigid body not change rotation
    if (rigidbody)
        rigidbody.freezeRotation = true;
}

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

        y = ClampAngle(y, yMinLimit, yMaxLimit);

        distance += Input.GetAxis ("Mouse ScrollWheel");
        if (distance < 3)
            distance = 3; 

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

        transform.rotation = rotation;
        transform.position = position;
    }
}

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);
}

It's not advisable to move the camera to zoom - you may intersect the objects being viewed.

Right, but it is perfect for a 3d turntable application because you do not change perspective and you can set a minimum distance.

u could simply go to Dastardlybanana.com it was a great find for me. download the weapons pack and in it is a aimmode thing. allowing u not only to aim in a scope. etc but also aim down the sights.

so lets say u wanna look through binoculars . U CAN. just find or make a picture with a scope texture but for binocs in other words a scope with 2 circles when u zoom in

in addition to d that u'll need of course the binoculars

hope i code help

PathKiller29

You can use this script

//Camera zoom script

  // Camera
  var cam : Camera;

 function Update()
 {
     if(Input.GetButtonDown("Fire2"))
     {
        cam.fieldOfView = 30;
     }
     if(Input.GetButtonUp("Fire2"))
     {
        cam.fieldOfView = 60;
     }
 }