- Home /
Question by
krishna_j · Jul 14, 2016 at 02:05 PM ·
unity 5mousefirst person controller
Moving First person controller Vertically using Mouse ?
The first person controller is moving horizontally but not vertically. Can someone check my code and tell me what i am doing wrong ``?
using UnityEngine;
using System.Collections;
public class FirstPerson : MonoBehaviour
{
public float movementSpeed = -5.0f;
public float mouseSensitivity = 5.0f;
float verticalRotation = 0;
public float upDownRange = 60.0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//rotation
float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(0, rotLeftRight, 0);
float rotUpDown = Input.GetAxis("Mouse Y") * mouseSensitivity;
Camera.main.transform.Rotate(-rotUpDown, 0, 0);
verticalRotation = -Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
//movement
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
Vector3 speed = new Vector3(sideSpeed, 0, forwardSpeed);
speed = transform.rotation * speed;
CharacterController cc = GetComponent<CharacterController>();
cc.SimpleMove(speed);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to disable FPS control but allow mouse to move and interact with GUI 1 Answer
First Person Controller - Mouse look doesn't work 1 Answer
Unity 2d Top-Down Mouse Aiming Stutters When Moving 2 Answers
Problem With First Person View Controller 1 Answer
Input.GetMouseButton(0) registering twice on relase? 4 Answers