Ejemplo n.º 1
0
    private void ChangeDirection(Vector2 relativePosition, ref Balle b)
    {
        Bounds bounds = GetComponent <Collider2D>().bounds;

        //if the right side of the collider is hit
        if (relativePosition.x > 0f && relativePosition.y <= bounds.max.y && relativePosition.y >= bounds.min.y)
        {
            //print ("Collided with the right side");
            b.SwapX();
        }
        //if the left side of the collider is hit
        else if (relativePosition.x < 0 && relativePosition.y <= bounds.max.y && relativePosition.y >= bounds.min.y)
        {
            //print ("Collided with the left side");
            b.SwapX();
        }

        //if the upper side of the collider is hit
        else if (relativePosition.y > 0 && relativePosition.x <= bounds.max.x && relativePosition.x >= bounds.min.x)
        {
            //print ("Collided with the upper side");
            b.SwapY();
        }
        //if the lower side of the collider is hit
        else if (relativePosition.y < 0 && relativePosition.x <= bounds.max.x && relativePosition.x >= bounds.min.x)
        {
            //print ("Collided with the lower side");
            b.SwapY();
        }
        else
        {
            b.SwapX();
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D c)
    {
        //print(name);

        if (c.gameObject.tag == "Balle")
        {
            if (aud != null)
            {
                aud.Play();
            }

            Balle b = c.gameObject.GetComponent <Balle>();
            b.SwapX();

            //if(Maths.FastApproximate(b.MirrorY, 0f, .1f) && name != "Main")
            //{
            //    b.appliedForce = new Vector3(b.appliedForce.x, b.appliedForce.y + addedForce);
            //}
            //else
            //{



            float f = Mathf.Abs(raquette.forceAddedToBall);
            if (f > .2f)
            {
                if (b.MirrorY != (int)Mathf.Sign(raquette.forceAddedToBall))
                {
                    b.MirrorY = (int)Mathf.Sign(raquette.forceAddedToBall);
                }
            }
            else
            {
                if (b.MirrorY == 0)
                {
                    b.MirrorY = (int)Mathf.Sign(raquette.forceAddedToBall);
                }

                f = 1f;
            }
            b.appliedForce = new Vector3(b.appliedForce.x, f);


            //}
        }
    }