Beispiel #1
0
    public void Launch(Vector3 from)
    {
        if (!reloadedObject.gameObject.activeInHierarchy)
        {
            reloadedObject.gameObject.SetActive(true);
            reloadedObject.transform.position = transform.position;
        }

        if (reloadedObject.objectState != ObjectState.InAir)
        {
            reloadedObject.StateChange(ObjectState.InAir);
        }
        if ((reloadedObject.objectTag & (int)(ObjectTag.Projectile)) == 0)
        {
            reloadedObject.objectTag += (int)(ObjectTag.Projectile);
        }


        Rigidbody2D rb2d = reloadedObject.GetComponent <Rigidbody2D>();

        if (rb2d)
        {
            Vector2 force = (transform.position - from) * launchSpeed;
            rb2d.AddForce(force, ForceMode2D.Impulse);
        }
    }
Beispiel #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ObjectBasic obj = collision.GetComponent <ObjectBasic>();

        if (obj)
        {
            if (obj.objectTag.isObjectTagIncluded(ObjectTag.AttachAble))
            {
                obj.transform.parent   = transform;
                obj.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .1f);
                WheelJoint2D joint2D = GetComponent <WheelJoint2D>();
                if (joint2D)
                {
                    Rigidbody2D rb2d = obj.GetComponent <Rigidbody2D>();
                    if (rb2d)
                    {
                        joint2D.connectedBody = rb2d;
                        obj.StateChange(ObjectState.FixedDynamic);
                        if (obj.objectTag.isObjectTagIncluded(ObjectTag.Projectile))
                        {
                            obj.objectTag -= (int)ObjectTag.Projectile;
                        }
                    }
                    else
                    {
                        Debug.Log(transform.ToString() + ".OnTriggerEnter2D : !rb2d");
                    }
                }
                else
                {
                    Debug.Log("! joint2D");
                }
            }
        }
    }
Beispiel #3
0
    public void Launch(ref ObjectBasic obj, Vector3 from)
    {
        if (!obj.gameObject.activeInHierarchy)
        {
            obj.gameObject.SetActive(true);
            obj.transform.position = transform.position;
        }

        Rigidbody2D rb2d = obj.GetComponent <Rigidbody2D>();

        if (rb2d)
        {
            Vector2 force = (transform.position - from) * launchSpeed;
            //rb2d.bodyType = RigidbodyType2D.Dynamic;
            //rb2d.AddForce(force, ForceMode2D.Impulse);
            rb2d.bodyType = RigidbodyType2D.Kinematic;
            rb2d.velocity = force;
            Debug.Log(transform.forward.ToString());
        }
    }