- Home /
Vertical axis not working properly
I'm trying to get my FPS controller to work properly, but I'm having trouble with the vertical axis. Either it doesn't work, or it over rotates and I end up with an upside down camera view. I'm using simple move because my robot character does not need to jump.
using UnityEngine; using System.Collections;
Public class PlayerController : monobehaviour {
public float MoveSpeed = 10f;
public float MouseSpeed = 5f;
public float Range = 60f
float pitch = 0f;
Void Start(){
Cursor.visible = false;
}
//as of right now vertical camera movement is not behaving correctly
void Update(){
//camera movement
float yaw = Input.GetAxis("Mouse X") * MouseSpeed;
transform.Rotate(yaw, 0 , 0);
pitch -= Input.GetAxis("Mouse Y") * MouseSpeed;
pitch = Mathf.Clamp(pitch, -range, range);
Camera.main.transform.localRotation = Quaternion.Euler(pitch, 0, 0);
//movement
float ForwardSpeed = Input.GetAxis("Vertical")*MoveSpeed;
float SidetoSide = Input.GetAxis("Hortizontal")*MoveSpeed;
//(fix this line)CharacterController cc = (SidetoSide, 0, ForwardSpeed);
Vector3 speed = new Vector3 speed;
speed = transform.rotation * speed;
cc.SimpleMove(speed);
}
}
Comment
Your answer
Follow this Question
Related Questions
Making a Model move with the Mouse 1 Answer
Use Mouse as Direction for Character Movement? 0 Answers
Why is my camera rotating like crazy? 2 Answers
FPS mouse look script for a space game 1 Answer
tring to make a jump pad in fps 1 Answer