I don’t really see a problem with the code, and there aren’t any errors in the console. But whenever I try to jump, nothing happens. Any suggestions or help would be awesome!
private CharacterController controller;
public float speed = 6.0f;
private Vector3 moveDir = Vector3.zero;
public float jumpSpd = 200.0f;
public Rigidbody rb;
private float gravity = 9.81f;
void Start(){
controller = GetComponent<CharacterController>();
rb.GetComponent<Rigidbody>();
}
void Update () {
Move ();
}
void Move(){
//makes the Vector3 use the WASD inputs
moveDir = new Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));
//creates a transform out of the input
moveDir = transform.TransformDirection(moveDir);
//controls how high or low the transform #'s are
moveDir *= speed;
//push down at a constant rate
moveDir.y -= gravity;
//If I jump the gravity will still be in effect
if (Input.GetKey (KeyCode.Space)){
//push up for 10 "steps" at the jump speed
rb.AddForce(Vector3.up * jumpSpd, ForceMode.Impulse);
}
//move the controller
controller.Move(moveDir * Time.deltaTime);
}