- Home /
Keyboard Camera control script question
I would like to make a camera with POV controls, similar to the first-person camera mode of Super Mario Galaxy (the character stands still, looking in all directions). I could probably do this easily with the Mouse Look script, but I want to use the arrow keys instead. I'v started with this script here:
http://www.unifycommunity.com/wiki/index.php?title=KeyboardCameraControl
I only have the Pitch and Yaw activated, not the Roll. However, the camera still seems to pivot around the Z axis. I've included pictures of what it looks like:
I don't want the POV to look like the character is sideways like this:
I'm not sure what the problem is. Thanks for any help.
Answer by testure · Jul 17, 2011 at 07:03 AM
Honestly, that script is overkill for what you're trying to do.
You can have a first-person freelook camera in just a few lines of code:
// C#, totally off the top of my head. might not work, just an example.
// disclaimer, disclaimer, etc, etc.
float deltaX = Input.GetAxis("Horizontal") * sensitivityX;
float deltaY = Input.GetAxis("Vertical") * sensitivityY;
transform.localEulerAngles = new Vector3(deltaY, deltaX , 0);
Note that you'd probably want a couple extra lines of code to prevent gimbal lock and rotation wrapping, but there are plenty of examples of that around, so I won't go into it. Just wanted to point out that the script you're using is way overkill.