i am modifying the std mouseorbit script to allow it to zoom in and out with the mouse wheel. I am using the following code to increase/decrease the distance of the camera, but it doesn’t seem to do anything.
You always have to set up your input axis before it will work. here is how: <link removed by mod as it’s now a website for cannabis after a decade or so>
It looks like there isn’t a way to get input from a mouse scroll wheel right now unless it is counted as a mouse button.
Well, I can’t get it to work. Has someone here tried to implement that already?
I have mapped the Element 11 with:
Name: Zoom In
Negative Button: mouse 4
Positive Button: mouse 5
Gravity: 1000 ?
Dead: 0
Sensitivity: 1
Type: Key / Mouse Button
Axis: X axis
Here is my script:
function LateUpdate () {
if (target) {
x += Input.GetAxis("Horizontal") * xSpeed * 0.02;
y -= Input.GetAxis("Vertical") * ySpeed * 0.02;
distance += Input.GetAxis("Zoom In"); // this is where I am trying to get mouse the wheel working
y = ClampAngle(y, yMinLimit, yMaxLimit);
distance = Mathf.Clamp(distance, minDistance, maxDistance);
var rotation = Quaternion.EulerAngles(y * Mathf.Deg2Rad, x * Mathf.Deg2Rad, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
In Unity 1.2.2 we added mouse wheel support and it was added to the default input settings. What might have happened is that the project was created with a previous version, so that the Input Settings didn’t have that axis setup.
In that case juse select Edit → Project Settings → Input
and in the inspectors titlebar choose Reset.
That will give you the default input settings which include mouse wheel support when using
Yes, I am using 1.2.2. and I have reset the input settings, but still nothing. The interesting part of the script looks like this:
function LateUpdate () {
if (target) {
x += Input.GetAxis("Horizontal") * xSpeed * 0.02;
y -= Input.GetAxis("Vertical") * ySpeed * 0.02;
distance += Input.GetAxis("Mouse ScrollWheel") * 300;
y = ClampAngle(y, yMinLimit, yMaxLimit);
distance = Mathf.Clamp(distance, minDistance, maxDistance);
var rotation = Quaternion.EulerAngles(y * Mathf.Deg2Rad, x * Mathf.Deg2Rad, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
Could it be problematic that I am running unity on an intel iMac? I am asking this also because unity keeps crashing if I do something wrong in the scripts. My guess is that normally unity shouldn’t crash if you mess with scripts, right?
My game has mouse wheel zooming (and I find the response for each wheel click to be about 1/8, compared to 1.0 for a keypress, so I had to compensate for that).
Input.GetAxis(“Mouse ScrollWheel”) worked fine for me. (Unity 1.2 and 1.5.)
Re Intel Macs - my wheel zoom works on them too.
Re script crashing: my G4 will do that sometimes too. Luckily it shows an error message leading to the solution, and I’ve never lost any data, but Unity will occasionally exit from a bad script (and this might have stopped with 1.5 but I’m not sure). I fix the script before I run the game again and I’m OK.