I’m trying to find out where to reset a boolean (touchWall) so that any time I’m not touching a wall in my game, I can jump. This is all fine and dandy, except any time I touch a wall, touchWall obviously gets set to true and I can’t jump any more at all. I can’t figure out where to turn touchWall back to false in my code (assuming somewhere in the OnCollisionEnter method). Below is the if statement for jumping and my OnCollisionEnter method. Thank you!
if (Input.GetKeyDown(KeyCode.Space) && onGround && !touchWall)
{
gameObject.rigidbody.velocity += new Vector3(0,jumpHeight,0);
onGround = false;
}
void OnCollisionEnter(Collision other)
{
if(other.transform.tag == "Enemy")
{
Die();
}
if(other.transform.tag == "Ground")
{
onGround = true;
touchWall = false;
}
if(other.transform.tag == "Wall")
{
touchWall = true;
}
}