I’m trying to create my own FPS controller and I’m using CharacterController.Move() to move. However it isn’t corresponding to the gameobject’s transform.rotation like I was expecting since I’ve assigned the gameobject’s transform.rotation = Quaternion.Euler(rot). The characterController moves but only along Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”). Does CharacterController.Move() operate independently from a gameobject’s transform.rotation? That’s what I think is happening. How would I be able to get the CharacterController to move while also following the gameobject’s transform.rotation?
using UnityEngine;
using System.Collections;
public class FirstPersonController : MonoBehaviour {
public Vector2 rot;
public Vector3 movement;
public float movementSpeed = 5.0f;
public float mouseSensitivity = 5.0f;
public float jumpAmount = 5.0f;
public float clampAngle = 90.0f;
public CharacterController characterController;
// Update is called once per frame
void Update () {
// Rotation
rot.y += Input.GetAxis("Mouse X") * mouseSensitivity;
rot.x += -Input.GetAxis("Mouse Y") * mouseSensitivity;
rot.x = Mathf.Clamp(rot.x, -clampAngle, clampAngle);
transform.rotation = Quaternion.Euler(rot);
movement.y += Physics.gravity.y * Time.deltaTime;
if( characterController.isGrounded && Input.GetButton("Jump") ) {
movement.y = jumpAmount;
}
movement = new Vector3(Input.GetAxis("Horizontal") * movementSpeed, movement.y, Input.GetAxis("Vertical") * movementSpeed);
characterController.Move(movement * Time.deltaTime );
}
}