public void FixedUpdate() { coyoteTime -= Time.deltaTime; RaycastHit hit; distanceToGround = 10f; if (Physics.SphereCast(transform.position + Vector3.up * 0.2f, 0.1f, -transform.up, out hit, 3f, collisionLayerMask)) { hit.collider.GetComponent <DropPlatform>()?.Drop(); distanceToGround = hit.distance; groundNormal = hit.normal; } if ((groundedTruth || rb.velocity.y < 0f) && distanceToGround <= groundingHeight + (groundedTruth ? 0.5f : 0f) && hit.normal.y > 0.7f) { if (!grounded) { OnLand.Invoke(-rb.velocity.y); // landCallback(-rb.velocity.y); } groundedTruth = true; } else { groundedTruth = false; } if (groundedTruth) { pid.UpdatePID(distanceToGround, Time.deltaTime, groundingHeightMod); rb.velocity += Vector3.up * pid.getCorrection(); coyoteTime = 0.1f; } grounded = coyoteTime > 0f; }
private void OnControllerColliderHit(ControllerColliderHit _hit) { if (_falling && !_landed) { LandEvent?.Invoke(transform.position); _landed = true; } }
void LandedOnGround(bool land) { LandEvent?.Invoke(land); }
void TriggerGrounded() { airJumpsRemaining = airJumps; //jumpedSteps = 0; LandEvent.Invoke(); }