Esempio n. 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);
        }
    }
Esempio n. 2
0
    public void Friction(IFrictionProperty property)
    {
        if (Math.Abs(this.direction.x) > 0.0f)
        {
            if (this.direction.x > 0)
            {
                this.direction.x -= (property.FrictionCoef.x * GameTime.deltaTime);
            }
            else
            {
                this.direction.x += (property.FrictionCoef.x * GameTime.deltaTime);
            }

            if (Mathf.Abs(this.direction.x) < this.frictionThreshold)
            {
                this.direction.x = 0.0f;
            }
        }
    }