I’m working on a game and while trying to implement player health, I somehow managed to break how jumping works in the game. I had it set that when the player is jumping, the player would not be able to jump a second time until they land. Now the player is able to jump an infinite number of times. Apparently it seems to be always set to false and is ignoring the ground tag. Here is the code that I have. Any idea what I did wrong?
public class Movement : MonoBehaviour
{
public GameObject character;
public Rigidbody _rb; //gets rigidbody from char
public float movementBoost = 0.0f;
public float rotationSpeed = 0.0f;
public float jumpHeight = 0.0f;
public bool isJumping = true;
public int numCollectables;
public int maxHealth;
public int curHealth;
// Use this for initialization
void Start()
{
character = gameObject;
_rb = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
_rb.AddForce(transform.forward * movementBoost);
}
if (Input.GetKey(KeyCode.A))
{
_rb.AddForce(-transform.right * movementBoost);//left
}
if (Input.GetKey(KeyCode.S))
{
_rb.AddForce(-transform.forward * movementBoost);//backward
}
if (Input.GetKey(KeyCode.D))
{
_rb.AddForce(transform.right * movementBoost);
}
if (Input.GetAxis("Mouse X") < 0 || Input.GetAxis("Mouse X") > 0) //or = ||
{
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * rotationSpeed);
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
if (Input.GetKeyDown (KeyCode.Space))
{
isJumping = true;
_rb.AddForce(transform.up * jumpHeight);
}
Debug.Log(isJumping);
}
public void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == ("Ground"))
{
isJumping = false;
}
if (other.gameObject.tag == ("Collectable"))
{
numCollectables++;
Destroy(other.gameObject);
}
}
}