- Home /
Question by
MaxWilder · Jul 23, 2016 at 06:34 AM ·
first-person-controllerfirst person controller
Problems creating first person controller
Hi! I'm new here and in Unity. I was creating a first person controller script with this code:
using UnityEngine; using System.Collections;
public class CharacterController : MonoBehaviour {
public float speed = 10f;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;
void Start () {
Cursor.lockState = CursorLockMode.Locked;
}
void Update () {
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0f, moveVertical);
movement.Normalize ();
transform.Translate (movement * Time.deltaTime * speed);
if (Input.GetKeyDown (KeyCode.Escape))
Cursor.lockState = CursorLockMode.None;
}
}
The problem is when I use it in my scene because when the character (a capsule) bumps into a corner, it starts to rotate indefinitely.
This image tries to explain it:
movimiento.jpg
(201.6 kB)
Comment