예제 #1
0
    void UpdateFoot(Foot foot, Transform hip)
    {
        if (!leftFoot.stepping && !rightFoot.stepping)
        {
            // NOTE: This threshold method is probably "better" for leg accuracy
            // because it works well with different elevations. But it makes visualizing
            // the leg boundaries harder.
            // float legLength = Vector3.Distance(hip.position, foot.transform.position);
            // if (legLength > maxLegLength)

            // TODO: Probably safer to just raycast
            float   distToGround = (capsuleHeight / 2f) + ((baseHeight + bounceOffset - crouchOffset) * 1.5f);
            Vector3 groundPos    = transform.position.AddY(-distToGround);
            float   stepDist     = Vector3.Distance(groundPos, foot.transform.position);
            if (stepDist > maxLegLength)
            {
                leftTurn = !leftTurn;
                Vector3 dir = hip.position + (movement.velocity.normalized * maxLegLength * 1.3f);
                dir.y += 100f;
                dir   += GetRandomOffset();

                int layerMask = 1 << 2;
                layerMask = ~layerMask;

                RaycastHit hit;
                if (Physics.Raycast(dir, Vector3.down, out hit, 1000f, layerMask))
                {
                    foot.StepTo(hit.point, stepSpeed);
                }
            }
        }
    }