Hey all, I’m sure this is an easy fix and I have just dome something silly but i cant find the answer on Google. I’m doing a simple fps to relearn how to use everything and for some reason the main camera is always 90 degrees left of the character model. the movement still works like the camera is pointing the right way and the pitch and yaw functionally work the fine though.
if that’s not making sense, imagine if you turn your head is permanently facing to the left.
here is the code and thanks for any help.
using UnityEngine;
using System.Collections;
public class FirstPersonController : MonoBehaviour {
public float movementspeed = 3.0f;
public float strafespeed = 2.0f;
public float mouseSensitivityH = 3.0f;
public float mouseSensitivityV = 3.0f;
public float pitchRange = 60.0f;
float desiredPitch = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Rotation
float rotYaw = Input.GetAxis("Mouse X") * mouseSensitivityH;
transform.Rotate(0, rotYaw, 0);
desiredPitch -= Input.GetAxis("Mouse Y") * mouseSensitivityV;
desiredPitch = Mathf.Clamp(desiredPitch, -pitchRange, pitchRange);
Camera.main.transform.localRotation = Quaternion.Euler(desiredPitch, 0, 0);
// Movement
float forwardSpeed = Input.GetAxis("Vertical") * movementspeed * -1;
float sideSpeed = Input.GetAxis("Horizontal") * strafespeed;
Vector3 speed = new Vector3( forwardSpeed, 0, sideSpeed);
speed = transform.rotation * speed;
CharacterController cc = GetComponent<CharacterController>();
cc.SimpleMove( speed );
}
}