Пример #1
0
    /*
     * \brief Called whilst a collision is taking place
     */
    public void CallOnCollisionStay(Collision collision, ref CWallJump wallJump)
    {
        m_canJump = true;

        /*
         * foreach (ContactPoint contact in collision.contacts) {
         *      Debug.DrawRay(contact.point, contact.normal, Color.green);
         *
         *      // don't slide on points that arnt on the floor
         *      float yContact = collision.transform.position.y - contact.point.y;
         *      if (yContact >= 0.5f)
         *              continue;
         *
         *      // slide down slopes
         *      if (!isNearly(contact.normal.x, 0.0f, 0.01f) || !isNearly(contact.normal.z, 0.0f, 0.01f) ) {
         *              CSceneObject sceneObject = contact.otherCollider.GetComponent<CSceneObject>();
         *              float scale = 1.0f;
         *              if (sceneObject != null)
         *                      scale = sceneObject.ExtraSlide;
         *
         *              float direction = contact.normal.x < 0.0f ? -1.0f : 1.0f;
         *              m_velocity += ((((1 - contact.normal.y) * 0.25f) * direction) * scale);
         *              return;
         *      }
         * }
         */

        if (!wallJump.GetCanWallJump())
        {
            foreach (ContactPoint contact in collision.contacts)
            {
                float yContact = collision.transform.position.y - contact.point.y;
                if (yContact < 0.5f)
                {
                    continue;
                }

                // we must be colliding if we are in this method
                m_colliding = true;
                m_velocity  = (-m_direction) * 0.25f;
                return;
            }
        }
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref CWallJump wallJump)
    {
        m_canJump = true;

        /*
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawRay(contact.point, contact.normal, Color.green);

            // don't slide on points that arnt on the floor
            float yContact = collision.transform.position.y - contact.point.y;
            if (yContact >= 0.5f)
                continue;

            // slide down slopes
            if (!isNearly(contact.normal.x, 0.0f, 0.01f) || !isNearly(contact.normal.z, 0.0f, 0.01f) ) {
                CSceneObject sceneObject = contact.otherCollider.GetComponent<CSceneObject>();
                float scale = 1.0f;
                if (sceneObject != null)
                    scale = sceneObject.ExtraSlide;

                float direction = contact.normal.x < 0.0f ? -1.0f : 1.0f;
                m_velocity += ((((1 - contact.normal.y) * 0.25f) * direction) * scale);
                return;
            }
        }
        */

        if (!wallJump.GetCanWallJump()) {
            foreach (ContactPoint contact in collision.contacts) {
                float yContact = collision.transform.position.y - contact.point.y;
                if (yContact < 0.5f)
                    continue;

                // we must be colliding if we are in this method
                m_colliding = true;
                m_velocity = (-m_direction) * 0.25f;
                return;
            }
        }
    }