#Yeah and I m asking where do you change

1 messages · Page 1 of 1 (latest)

bleak aspen
#

Oh im sorry its ```private bool readyToJump()
{
//return transform.Find("GroundCheck").GetComponent<GroundCheck>().isGrounded;

    float extraHeightText = 1f;
    RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down, extraHeightText, groundMask);

    Color rayColor;
    if (raycastHit.collider != null)
    {
        rayColor = Color.green;
    }
    else
    {
        rayColor = Color.red;
    }
    Debug.DrawRay(boxCollider2d.bounds.center + new Vector3(boxCollider2d.bounds.extents.x, 0), Vector2.down * (boxCollider2d.bounds.extents.y + extraHeightText), rayColor);
    Debug.DrawRay(boxCollider2d.bounds.center - new Vector3(boxCollider2d.bounds.extents.x, 0), Vector2.down * (boxCollider2d.bounds.extents.y + extraHeightText), rayColor);
    Debug.DrawRay(boxCollider2d.bounds.center - new Vector3(boxCollider2d.bounds.extents.x, boxCollider2d.bounds.extents.y + extraHeightText), Vector2.right * (boxCollider2d.bounds.extents.x * 2f), rayColor);

    Debug.Log(raycastHit.collider);
    return raycastHit.collider != null;
}
loud tapir
#

I suppose you have grounded = readyToJump() somewhere..?

bleak aspen
#

no readyToJump() is my grounded name it is being called when it needs to be

#

like if (Input.GetMouseButton(0) && readyToJump())

loud tapir
#
bool isGrounded = false;

void Update()
{
  // Store the previous frame's grounded state
  bool wasGrounded = isGrounded;
  // Update the current grounded state
  isGrounded = readyToJump();
  
  // Now we can compare current to last state
  if (!wasGrounded && isGrounded)
  {
    // Just became grounded
  }
  else if (wasGrounded && !isGrounded)
  {
    // Just left the ground
  }
}
#

Does that make sense?

#

Then you wouldn't call readyToJump anymore, you just check isGrounded

#

Only call it once per frame

#

Could probably just do it in FixedUpdate actually

bleak aspen
#

Yeah, that makes sense

#

and is better what i have now