Пример #1
0
    private void OnCollision(GameObject obj)
    {
        Debug.Log("Checking collisions");

        //Get the component of the object we collided
        IStickProperty    stickProperty    = obj.GetComponent <IStickProperty>();
        IBounceProperty   bounceProperty   = obj.GetComponent <IBounceProperty>();
        IFrictionProperty frictionProperty = obj.GetComponent <IFrictionProperty>();
        ISlipProperty     slipProperty     = obj.GetComponent <ISlipProperty>();

        if (Math.Abs(Vector3.Angle(this.normalHit, this.finalDirection)) > 90.0f)
        {
            if (bounceProperty != null)
            {
                Debug.Log("Bounce");
                this.Bounce(new Collision(), bounceProperty);
            }
            else if (stickProperty != null && !this.isGrounded && !this.isStick)
            {
                Debug.Log("Stick");
                this.Stick(stickProperty);
            }
        }
        else if (frictionProperty != null && this.direction != Vector3.zero)
        {
            Debug.Log("Friction");
            this.Friction(frictionProperty);
        }
        if (slipProperty != null && !this.isSlip)
        {
            Debug.Log("Slip");
            this.Slip(slipProperty);
        }
    }
Пример #2
0
    public void Bounce(Collision collision, IBounceProperty property)
    {
        int normalX = Mathf.RoundToInt(collision.contacts[0].normal.x);

        if (Math.Abs(normalX) == 1)
        {
            Debug.Log("Force added");
            this.rigidbody.AddForce(Vector3.up * property.UpwardForceAdded, ForceMode.Impulse);
        }
    }
Пример #3
0
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Collision !");
        switch (collision.gameObject.tag)
        {
        case GameObjectsTags.Stick:
            //Stick Behaviour
            IStickProperty stickProperty = collision.gameObject.GetComponent <StickProperty>();
            if (stickProperty != null)
            {
                if (stickProperty.IsEnable)
                {
                    Debug.Log("Stick !");
                    this.Stick(collision, stickProperty);
                }
            }
            break;

        case GameObjectsTags.Bounce:
            //Bounce Behaviour
            IBounceProperty bounceProperty = collision.gameObject.GetComponent <BounceProperty>();
            if (bounceProperty != null)
            {
                if (bounceProperty.IsEnable)
                {
                    Debug.Log("Bounce !");
                    this.Bounce(collision, bounceProperty);
                }
            }
            break;

        case GameObjectsTags.Slip:
            //Slip Behaviour
            this.rigidbody.useGravity = false;
            break;

        default:
            break;
        }
    }