my jumping code here has always worked before on other kinds of objects but for some reason i cant get it working, maybe there is something im missing in this code thats stopping me from jumping?
using UnityEngine;
using System.Collections;
public class thirdpersonmove : MonoBehaviour
{
private void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "level") {
jumpone = false;
jumptwo = false;
}
}
public float speed = 6.0F;
public float jumpSpeed;
public float gravity = 20.0F;
private Rigidbody rgb;
private Vector3 moveDirection = Vector3.zero;
private bool jumpone;
private bool jumptwo;
private void Start()
{
rgb = gameObject.GetComponent<Rigidbody>();
jumptwo = false;
jumpone = false;
}
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
{
if (jumpone == true && jumptwo == false)
{
rgb.AddForce(transform.up * jumpSpeed);
jumptwo = true;
Debug.Log("jumping");
}
if (jumpone == false && jumptwo == false)
{
rgb.AddForce(transform.up * jumpSpeed);
jumpone = true;
Debug.Log("jumping");
}
}
}
}