I have a very specific question for you guys, I’ve been following a tutorial which has allowed me to implement a free look camera absolutely fine and there are lots of tutorials on how to get zooming working with the mouse wheel.
The tutorial I’ve been following, did a great job actually so kudos to this guy
However I haven’t been able to find anything on how to translate with the mouse wheel and have the camera move up and down, this is probably because it’s quite an uncommon game feature, everyone only tends to use the mouse wheel to zoom in games as we know.
Startopia
Here in the video after a short while you can see that the player in this old game is using the mouse scroll to move vertically up and down quickly, this gets rid of that annoying problem I find dealing with the Y axis when in free look because normally you’d have to go backwards in order to get to the height you want.
I’m continuing to search for information but I’d be grateful if you guys helped me out with this particular thing, it’s just a matter of me understanding the syntax for it and then it will be easy to implement.
Can’t this be done using the Input.GetAxis(“Mouse ScrollWheel”);
And then use this value to maybe lerp the camera up or down depending if it is positive or negative?
I had a look at that but that’s the thing, when I tried implementing it it would throw up errors so it obviously needs to be done in a pretty specific way which is why I’m asking around for the syntax, thanks for replying!
I would have thought it would be a simple Transform.y or something based on the mousescroll as you described, but yeah, as I said, unity didn’t like it very much, I just haven’t done anything much yet with the mouse wheel code itself. I’ll see if I can’t use lerp and just mess around, there might be a video floating around on that specific thing.
That very same script you used there is working for me, I noticed that the values for a normal wheel scrolling are pretty low (something like 0.1) so make sure to put enough sensivity.
Oh I am very happy now, got it all completely working, here it is in full syntax for future reference guys, hope this helps anyone in the future, simply adjust in Unity itself as it’s a public variable to your liking.
using UnityEngine;
using System.Collections;
public class FreeLook : MonoBehaviour {
public float speed = 50.0f;
public float sensitivity = 20.0f;
public bool inverted = false;
public float scrollSensitivity = 10.0f;
private Vector3 lastMouse = new Vector3(225,225,225);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
lastMouse = Input.mousePosition - lastMouse;
if (!inverted) lastMouse.y = - lastMouse.y;
lastMouse *= sensitivity;
lastMouse = new Vector3 (transform.eulerAngles.x + lastMouse.y, transform.eulerAngles.y + lastMouse.x, 0);
transform.eulerAngles = lastMouse;
lastMouse = Input.mousePosition;
Vector3 dir = new Vector3 ();
if (Input.GetKey (KeyCode.W)) dir.z += 1.0f;
if (Input.GetKey (KeyCode.S)) dir.z -= 1.0f;
if (Input.GetKey (KeyCode.A)) dir.x -= 1.0f;
if (Input.GetKey (KeyCode.D)) dir.x += 1.0f;
dir.Normalize ();
transform.Translate(dir * speed * Time.deltaTime);
transform.position += new Vector3(0f, Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity * Time.deltaTime, 0f);
}
}
Once grozzler explained it to me it was fine, I just needed to know how to implement it, full credit goes to him.