- Home /
Question by
giants1 · Dec 10, 2012 at 05:54 AM ·
javascriptkeyboardcontrolszoom
Javascript coding on how to zoom in using keyboard
Trying to make a game similar to Slender. What is the coding to zoom using any keyboard command using javascript coding.
Comment
Best Answer
Answer by clunk47 · Dec 10, 2012 at 08:32 AM
Here's a simple javascript I put together. This uses vertical axis, which is W and S, as well as Up and Down Arrow Keys. Use these keys to zoom in and out. This uses Field of view to zoom in and out, keeping the camera in it's place. This script also has min and max zoom. Attach this script to the main camera in your scene.
private var cam : Camera;
var fov : float = 60f;
var zoom_speed : float = 60.0f;
var zoom_min : float = 30.0f;
var zoom_max : float = 90.0f;
function Start ()
{
cam = this.camera;
}
function Update ()
{
cam.fieldOfView = fov;
if(fov >= zoom_max)
fov = zoom_max;
if(fov <= zoom_min)
fov = zoom_min;
if(Input.GetAxis("Vertical") > 0)
fov+= zoom_speed * Time.smoothDeltaTime;
else if(Input.GetAxis("Vertical") < 0)
fov-= zoom_speed * Time.smoothDeltaTime;
}
Hi, i tried this code on visual basic 2015 version but its not working as it gives me error as follows in the picture below. So what i should change to be compitable with the current VB version? Thanks
jaav-error.png
(56.2 kB)