I have tried several scripts but this is the one that has allowed me to get the character to fall:
public CharacterController controller;
private Vector3 direction;
public float speed = 8;
private Vector3 moveDirection = Vector3.zero;
public bool isGrounded;
Vector3 moveVector;
public Vector3 jump;
public float jumpForce = 2.0F;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
private Rigidbody rb;
// Update is called once per frame
void Update()
{
moveVector = Vector3.zero;
float hInput = Input.GetAxis("Horizontal");
direction.x = hInput * speed;
if (controller.isGrounded == true && Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
if (isGrounded == false)
{
//Add our gravity Vecotr
moveVector += Physics.gravity;
}
controller.Move(moveVector * Time.deltaTime);
controller.Move(direction * Time.deltaTime);
}
void OnCollisionEnter(Collision other)
{
isGrounded = true;
}
void OnCollisionExit(Collision other)
{
isGrounded = false;
}
Please help me figure this out.