private void CheckGrounded() { float boxHeight = Mathf.Clamp(groundDetectionHeight - (rb2d.velocity.y * Time.fixedDeltaTime), groundDetectionHeight, 5f); debugGroundBox = boxHeight; Vector2 boxOrigin = (Vector2)transform.position + boxCollider.offset; boxOrigin.y += groundDetectionHeight + (rb2d.velocity.y * Time.fixedDeltaTime); RaycastHit2D[] boxHits = Physics2D.BoxCastAll(boxOrigin, new Vector2(boxCollider.size.x, boxHeight), 0f, Vector2.down, boxHeight + (boxCollider.size.y / 2f), groundedLayer); movingPlatform = null; foreach (RaycastHit2D boxHit in boxHits) { if (boxHit) { debugGroundedPoint.Add(boxHit.point); isGrounded = true; if (boxHit.collider.gameObject.tag == "Moving") { movingPlatform = boxHit.collider.transform.parent.GetComponent <Pathfollower>(); } } } }
void Start() { rbd = GetComponent <Rigidbody>(); _pathfollower = GetComponent <Pathfollower>(); }