Exemple #1
0
    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;
    }
Exemple #2
0
 private void OnControllerColliderHit(ControllerColliderHit _hit)
 {
     if (_falling && !_landed)
     {
         LandEvent?.Invoke(transform.position);
         _landed = true;
     }
 }
Exemple #3
0
 void LandedOnGround(bool land)
 {
     LandEvent?.Invoke(land);
 }
 void TriggerGrounded()
 {
     airJumpsRemaining = airJumps;
     //jumpedSteps = 0;
     LandEvent.Invoke();
 }