I am creating my own FPS Controller because a) I could use the experience and b) the one provided by Unity attached sticks of butter to their feet. The only problem is, I can’t get it to move.
So, here’s my code.
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
public float speed;
public float jumpForce;
bool jumping;
Rigidbody playerRigidbody;
void Awake () {
playerRigidbody = GetComponent <Rigidbody> ();
}
void FixedUpdate () {
if (Input.GetKey("Space") && !jumping) {
playerRigidbody.AddForce(transform.up * jumpForce);
jumping = true;
}
if (Input.GetKey("w")) playerRigidbody.AddForce(transform.forward * speed);
if (Input.GetKey("a")) playerRigidbody.AddForce(-transform.right * speed);
if (Input.GetKey("s")) playerRigidbody.AddForce(-transform.forward * speed);
if (Input.GetKey("d")) playerRigidbody.AddForce(transform.right * speed);
}
}
Also (because I know someone’s going to ask), I have already tried changing the speed and jumpForce values.