Does anyone know where I can get an all-keyboard first-person controller? I have a game I want in a web site, and it can get confusing/annoying with the mouse (http://coolfone.mobi/fpmaze6/). I basically want the right and left arrows to rotate and to have the mouse basically do nothing. Thanks.
Why not write it yourself? Just rotate by Input.GetAxis("Horizontal"), and translate forward by Input.GetAxis("Vertical") (each suitably scaled for speed and multiplied by Time.deltaTime, of course).
Thanks for the help. I wrote some code for the Wolfensteinish controls, and I put a new version up here: http://coolfone.mobi/fpmaze7/ Here’s the code: Code (CSharp): using UnityEngine; using System.Collections; public class KBMove : MonoBehaviour { public float moveSpeed = 5f; public float rotateSpeed = 2f; CharacterController _characterController; // Use this for initialization void Start () { _characterController = GetComponent<CharacterController> (); } // Update is called once per frame void Update () { float horiz = Input.GetAxis ("Horizontal"); this.transform.RotateAround (transform.position, Vector3.up, horiz * rotateSpeed); float vert = Input.GetAxis ("Vertical"); _characterController.Move (transform.forward * Time.fixedDeltaTime * vert * moveSpeed); } }
Pretty good. But, you shouldn't use Time.fixedDeltaTime in Update; use Time.deltaTime instead. And you should use it for the rotation as well, otherwise your rotation rate will depend on the frame rate, which is a bad thing. Otherwise, nice job!
I decided to put the rotation in Update() and the movement in FixedUpdate() since that’s what FirstPersonController.cs seems to do. Here’s what I have now: Code (CSharp): using UnityEngine; using System.Collections; public class KBMove : MonoBehaviour { public float moveSpeed = 5f; public float rotateSpeed = 100f; CharacterController _characterController; // Use this for initialization void Start () { _characterController = GetComponent<CharacterController> (); } // Update is called once per frame void Update () { float horiz = Input.GetAxis ("Horizontal"); this.transform.RotateAround (transform.position, Vector3.up, horiz * rotateSpeed * Time.deltaTime); } void FixedUpdate() { float vert = Input.GetAxis ("Vertical"); _characterController.Move (transform.forward * Time.fixedDeltaTime * vert * moveSpeed); } } I put the new version up over here: http://coolfone.mobi/fpmaze8/ Let me know if you have any thoughts on it. Thanks.