Exemplo n.º 1
0
    public void Stick(IStickProperty property)
    {
        if (property.IsEnable)
        {
            int normalX = Mathf.RoundToInt(this.normalHit.x);
            int normalY = Mathf.RoundToInt(this.normalHit.y);

            if (Math.Abs(normalX) == 1 || normalY == -1)
            {
                this.stickTime = 0.0f;
                this.isStick   = true;
            }
            else if (normalY == 1)
            {
                this.isGrounded = true;
            }
            else
            {
                this.stickTime = 0.0f;
                this.isStick   = true;
            }

            //Vector3 offset = (this.transform.position - this.hitPoint);
            //this.transform.position = this.hitPoint + offset;
            this.direction = Vector3.zero;
        }
    }
Exemplo n.º 2
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);
        }
    }
Exemplo n.º 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;
        }
    }
Exemplo n.º 4
0
 public void Stick(Collision collision, IStickProperty property)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 public void Stick(Collision collision, IStickProperty property)
 {
     this.isStick = true;
     this.rigidbody.useGravity = false;
     this.rigidbody.velocity   = Vector3.zero;
 }