Exemplo n.º 1
0
    void RaycastGround()
    {
        RaycastHit hit;
        bool       old_grounded = grounded;

        if (Physics.Raycast(transform.position + Vector3.up * groundDist, Vector3.down, out hit, groundDist * 2, groundLayer))
        {
            grounded = Vector3.Angle(hit.normal, Vector3.up) <= slopeLimit;

            // Push away from the cliff
            //outsideMotion = hit.normal.SetY(0) * slopeForce * (1 - Mathf.Abs(hit.normal.y));

            GameObject main = hit.collider.attachedRigidbody ? hit.collider.attachedRigidbody.gameObject : hit.collider.gameObject;

            // Send touch events
            _TouchListener listener = main.GetComponent <_TouchListener>();
            if (listener)
            {
                listener.Touch(this);
            }

            // Get the current platform
            platform = main.GetComponent <_Platform>();

            lastHit = hit;
        }
        else
        {
            outsideMotion = Vector3.zero;
            grounded      = false;
            platform      = null;
            lastHit       = null;
        }

        // /grounded/ changed
        if (old_grounded != grounded)
        {
            if (grounded && sound)
            {
                sound.OnGrounded();
            }
        }
    }