- Home /
Free Look Camera
I'm attempting to make a free look camera (like you might find in Counter Strike after dieing), but I'm having a problem of when I look around while moving, my camera will sometimes just flip over. How can I make it so the camera stays relatively flat while looking around?
Here is what I'm using now:
var turnSpeed = 10.0; var moveSpeed = 10.0; var mouseTurnMultiplier = 1;
private var x : float; private var z : float; function Update () { // x is used for the x axis. set it to zero so it doesn't automatically rotate x = 0;
// check to see if the W or S key is being pressed.
z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed * 10;
// Move the character forwards or backwards
transform.Translate(0, 0, z);
zx = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed * 10;
// Move the character forwards or backwards
transform.Translate(zx, 0, 0);
// Get the difference in horizontal mouse movement
x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier/10;
y = Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier/10;
// rotate the character based on the x value
transform.Rotate(-y, x, 0);
}
Answer by Rennat · Dec 02, 2010 at 07:20 PM
Simplify your script just to manage movement, then add the MouseLook script from the standard assets library and voila!
I'm still getting some tilt, but it's not as bad. I'll just live with it for now.
Your answer
Follow this Question
Related Questions
My camera is not linking with my movement 0 Answers
Unity Editor Like Camera Script? 1 Answer
Jerky 3rd Person Camera Following Movement and Rotation 0 Answers
Camera View Problem 0 Answers
Camera isn't following mouse in FPS 0 Answers