Ejemplo n.º 1
0
    void ThrowObject()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {
            Vector3 v3 = Input.mousePosition;
            v3.z = 10.0f;
            if (!onDrawLine)
            {
                throwStart = Camera.main.ScreenToWorldPoint(v3);
                onDrawLine = true;
            }

            throwEnd = Camera.main.ScreenToWorldPoint(v3);
        }
        else
        {
            if (onDrawLine)
            {
                onDrawLine = false;

                if (objectBasic && objectBasic.transform.parent == transform)
                {
                    objectBasic.transform.parent = null;

                    Vector2 v2 = throwStart - throwEnd;
                    objectBasic.StateChange(ObjectState.Free);
                    objectBasic.AddVelocity(v2 * 2, ForceMode2D.Impulse);

                    objectBasic = null;
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        ObjectBasic obj = collision.GetComponent <ObjectBasic>();

        if (obj)
        {
            if (!obj.transform.parent)
            {
                if (objectBasic)
                {
                    Vector2 distance  = transform.position - objectBasic.transform.position;
                    Vector2 distance2 = transform.position - obj.transform.position;
                    if (distance.magnitude > distance2.magnitude)
                    {
                        objectBasic = obj;
                    }
                }
                else
                {
                    if (!obj.transform.parent)
                    {
                        objectBasic = obj;
                    }
                }
            }
        }
    }
Ejemplo n.º 3
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");
                }
            }
        }
    }
Ejemplo n.º 4
0
    ObjectBasic AddObject()
    {
        ObjectBasic obb = Instantiate <ObjectBasic>(objectToPool);

        obb.gameObject.SetActive(false);
        pooledObj.Add(obb);
        return(obb);
    }
Ejemplo n.º 5
0
    public void GrabObject()
    {
        if (itemDetector.objectBasic)
        {
            objectBasic = itemDetector.objectBasic;
            itemDetector.objectBasic = null;

            objectBasic.transform.parent = transform;
            objectBasic.StateChange(ObjectState.FixedKinematic);
        }
    }
Ejemplo n.º 6
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        ObjectBasic obj = collision.transform.GetComponent <ObjectBasic>();

        if (obj)
        {
            if (obj.objectTag.isObjectTagIncluded(ObjectTag.Box) || obj.objectTag.isObjectTagIncluded(ObjectTag.Player))
            {
                ActivateObject();
            }
            Debug.Log(obj.ToString() + " : is exit");
        }
    }
Ejemplo n.º 7
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        ObjectBasic obj = collision.GetComponent <ObjectBasic>();

        if (obj)
        {
            if (objectBasic)
            {
                if (obj.transform == objectBasic.transform)
                {
                    objectBasic = null;
                }
            }
        }
    }
Ejemplo n.º 8
0
    void ReloadBullet()
    {
        if (launcher && ammo && (state & (int)TurretState.Reloading) == 0)
        {
            ObjectBasic obj = ammo.GetInActivatedObject();
            obj.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .1f);

            if (obj.objectState != ObjectState.FixedKinematic)
            {
                obj.StateChange(ObjectState.FixedKinematic);
            }

            obj.gameObject.SetActive(true);
            launcher.reloadedObject = obj;
            if ((state & (int)TurretState.Reloading) == 0)
            {
                state += (int)TurretState.Reloading;
            }
        }
    }
Ejemplo n.º 9
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());
        }
    }
Ejemplo n.º 10
0
    void VerticalCollisions(ref Vector2 moveAmount)
    {
        float directionY = Mathf.Sign(moveAmount.y);
        float rayLength  = Mathf.Abs(moveAmount.y) + skinWidth;

        for (int i = 0; i < verticalRayCount; i++)
        {
            RaycastHit2D hit = CollisionCheck(moveAmount, i, collisionMask, false);

            if (hit && hit.transform != transform)
            {
                ObjectBasic ob = hit.transform.GetComponent <ObjectBasic>();

                if (ob)
                {
                    if ((ob.objectTag & (int)ObjectTag.Circle) > 0)
                    {
                        if (moveAmount.y > 0)
                        {
                            continue;
                        }
                    }
                    if ((ob.objectTag & (int)ObjectTag.Box) > 0)
                    {
                        if (moveAmount.y > 0)
                        {
                            continue;
                        }
                    }
                }


                if (hit.collider.tag == "Through")
                {
                    if (directionY == 1 || hit.distance == 0)
                    {
                        continue;
                    }
                    if (collisions.fallingThroughPlatform)
                    {
                        continue;
                    }
                    if (playerInput.y == -1)
                    {
                        collisions.fallingThroughPlatform = true;
                        Invoke("ResetFallingThroughPlatform", .5f);
                        continue;
                    }
                }

                moveAmount.y = (hit.distance - skinWidth) * directionY;
                rayLength    = hit.distance;

                if (collisions.climbingSlope)
                {
                    moveAmount.x = moveAmount.y / Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(moveAmount.x);
                }

                collisions.below = directionY == -1;
                collisions.above = directionY == 1;
            }
        }

        if (collisions.climbingSlope)
        {
            float directionX = Mathf.Sign(moveAmount.x);
            rayLength = Mathf.Abs(moveAmount.x) + skinWidth;
            Vector2      rayOrigin = ((directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight) + Vector2.up * moveAmount.y;
            RaycastHit2D hit       = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, collisionMask);

            if (hit)
            {
                float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
                if (slopeAngle != collisions.slopeAngle)
                {
                    moveAmount.x           = (hit.distance - skinWidth) * directionX;
                    collisions.slopeAngle  = slopeAngle;
                    collisions.slopeNormal = hit.normal;
                }
            }
        }
    }
Ejemplo n.º 11
0
 virtual public void OperateObject(ObjectBasic obj)
 {
 }
Ejemplo n.º 12
0
 virtual public void ActivateObject(ObjectBasic obj)
 {
 }
Ejemplo n.º 13
0
 virtual public void DeActivateObject(ObjectBasic obj)
 {
     obj.DeActivate();
 }
Ejemplo n.º 14
0
    void HorizontalCollisions(ref Vector2 moveAmount)
    {
        float directionX = collisions.faceDir;
        float rayLength  = Mathf.Abs(moveAmount.x) + skinWidth;

        if (Mathf.Abs(moveAmount.x) < skinWidth)
        {
            rayLength = 2 * skinWidth;
        }

        for (int i = 0; i < horizontalRayCount; i++)
        {
            RaycastHit2D eventHit = CollisionCheck(moveAmount * 2, i, collisionMask);


            RaycastHit2D hit = CollisionCheck(moveAmount, i, collisionMask);

            if (hit)
            {
                ObjectBasic ob = hit.transform.GetComponent <ObjectBasic>();
                if (ob)
                {
                    if ((ob.objectTag & (int)ObjectTag.Circle) > 0)
                    {
                        continue;
                    }
                    if ((ob.objectTag & (int)ObjectTag.Box) > 0)
                    {
                        continue;
                    }
                }
                float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);


                if (i == 0 && slopeAngle <= maxSlopeAngle)
                {
                    if (collisions.descendingSlope)
                    {
                        collisions.descendingSlope = false;
                        moveAmount = collisions.moveAmountOld;
                    }
                    float distanceToSlopeStart = 0;
                    if (slopeAngle != collisions.slopeAngleOld)
                    {
                        distanceToSlopeStart = hit.distance - skinWidth;
                        moveAmount.x        -= distanceToSlopeStart * directionX;
                    }
                    ClimbSlope(ref moveAmount, slopeAngle, hit.normal);
                    moveAmount.x += distanceToSlopeStart * directionX;
                }

                if (!collisions.climbingSlope || slopeAngle > maxSlopeAngle)
                {
                    moveAmount.x = (hit.distance - skinWidth) * directionX;
                    rayLength    = hit.distance;

                    if (collisions.climbingSlope)
                    {
                        moveAmount.y = Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * (Mathf.Abs(moveAmount.x));
                    }

                    collisions.left  = directionX == -1;
                    collisions.right = directionX == 1;
                }
            }
        }
    }