- Home /
ScrollWheel Input reseting?
I am trying to use the mouse scroll wheel to zoom my camera in, but when I tryed to scroll, the "Input.GetAxis" variable would change, but after I stopped scrolling it would reset back to zero, the camera zoom reseting with it. I do not know why this is happening, so any suggestions are welcome. Here is my script:
static var haveOverrided : boolean = false;
var sensitivityX : float = 15.0; var sensitivityY : float = 15.0;
var minimumX : float = -360.0; var maximumX : float = 360.0;
var minimumY : float = -60.0; var maximumY : float = 45.0;
private var rotationY : float = 0.0; private var rotationX : float = 0.0;
function Update () { if (Input.GetButton ("Fire2")) { haveOverrided = true; rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") sensitivityX; rotationY += Input.GetAxis("Mouse Y") sensitivityY; rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); } transform.localEulerAngles = Vector3(-rotationY, rotationX, 0); mouseScroll = Input.GetAxis ("Mouse ScrollWheel"); var cameraZoom = Camera.main; cameraZoom.camera.fieldOfView = mouseScroll*20+60; print (mouseScroll); }
Answer by DaveA · Jan 29, 2011 at 05:57 AM
If the value is zero when not moving, then use that value as a 'delta', accumulate it to a stored value (assuming it goes negative if moved in the opposite direction). Something like mouseScroll += Inout.GetAxis("MouseScrollWheel"); (but you'll need to tweak it)
You are absolutely right. The mouse wheel is a delta input like $$anonymous$$ouse X or $$anonymous$$ouse Y. It returns how much that axis has been moved since the last frame.
thanks, that works great! I tweaked it to mouseScroll-=Input.GetAxis("$$anonymous$$ouse ScrollWheel") since += was inverted.
Your answer
Follow this Question
Related Questions
How to move camera on local z axis 2 Answers
Mouse wheel zoom 1 Answer
Keep Player + Party and/or Targeted Enemies in Camera Focus 1 Answer
Avoid/Minimize Sprites extrapolation in 2D while camera changes size 0 Answers
Basic Camera rotation and Zoom 0 Answers