예제 #1
0
    /// <summary>
    /// Shows the cornors of the platform
    /// </summary>
    public void OnDrawGizmos()
    {
        Gizmos.color = Color.blue;
        Gizmos2D.DrawCircle(new Vector2(Physics2DExtra.Left(gCollider), Physics2DExtra.Top(gCollider)), 0.1f);

        Gizmos.color = Color.red;
        Gizmos2D.DrawCircle(new Vector2(Physics2DExtra.Right(gCollider), Physics2DExtra.Top(gCollider)), 0.1f);

        Gizmos.color = Color.green;
        Gizmos2D.DrawCircle(new Vector2(Physics2DExtra.Left(gCollider), Physics2DExtra.Bottom(gCollider)), 0.1f);

        Gizmos.color = Color.yellow;
        Gizmos2D.DrawCircle(new Vector2(Physics2DExtra.Right(gCollider), Physics2DExtra.Bottom(gCollider)), 0.1f);
    }
예제 #2
0
    /// <summary>
    /// Moves the platform, pushes entities
    /// </summary>
    /// <param name="xAmount"></param>
    /// <param name="yAmount"></param>
    private void Move(float xAmount, float yAmount)
    {
        subPixelVelocity.x += xAmount;
        subPixelVelocity.y += yAmount;

        float moveX = Mathf.Round(subPixelVelocity.x * Physics2DExtra.PIXEL_SIZE) / Physics2DExtra.PIXEL_SIZE; // In Units
        float moveY = Mathf.Round(subPixelVelocity.y * Physics2DExtra.PIXEL_SIZE) / Physics2DExtra.PIXEL_SIZE; // In Units

        if (moveX != 0 || moveY != 0)
        {
            List <Entity2D> riding      = GetAllRidingEntities();
            Entity2D[]      AllEntities = FindObjectsOfType <Entity2D>();

            //May need to change
            gCollider.isTrigger = true;

            //X
            if (moveX != 0)
            {
                //Moveplatform
                subPixelVelocity.x -= moveX;
                transform.position += new Vector3(moveX, 0, 0);
                Physics2D.SyncTransforms();

                if (moveX > 0)
                {
                    foreach (Entity2D ent in AllEntities)
                    {
                        if (Physics2DExtra.PlaceMeeting(gCollider, Vector2.zero, entitiyLayer, ent.bCollider, true))
                        {
                            ent.MoveX(Physics2DExtra.Right(gCollider) - Physics2DExtra.Left(ent.bCollider));
                        }
                        else if (riding.Contains(ent))
                        {
                            ent.MoveX(moveX);
                        }
                    }
                }
                else if (moveX < 0)
                {
                    foreach (Entity2D ent in AllEntities)
                    {
                        if (Physics2DExtra.PlaceMeeting(gCollider, Vector2.zero, entitiyLayer, ent.bCollider, true))
                        {
                            ent.MoveX(Physics2DExtra.Left(gCollider) - Physics2DExtra.Right(ent.bCollider));
                        }
                        else if (riding.Contains(ent))
                        {
                            ent.MoveX(moveX);
                        }
                    }
                }
            }

            //Y
            if (moveY != 0)
            {
                //Moveplatform
                subPixelVelocity.y -= moveY;
                transform.position += new Vector3(0, moveY, 0);
                Physics2D.SyncTransforms();

                if (moveY > 0)
                {
                    foreach (Entity2D ent in AllEntities)
                    {
                        if (Physics2DExtra.PlaceMeeting(gCollider, Vector2.zero, entitiyLayer, ent.bCollider, true))
                        {
                            ent.MoveY(Physics2DExtra.Top(gCollider) - Physics2DExtra.Bottom(ent.bCollider));
                        }
                        else if (riding.Contains(ent))
                        {
                            ent.MoveY(moveY);
                        }
                    }
                }
                else
                {
                    foreach (Entity2D ent in AllEntities)
                    {
                        if (Physics2DExtra.PlaceMeeting(gCollider, Vector2.zero, entitiyLayer, ent.bCollider, true))
                        {
                            ent.MoveY(Physics2DExtra.Bottom(gCollider) - Physics2DExtra.Top(ent.bCollider));
                        }
                        else if (riding.Contains(ent))
                        {
                            ent.MoveY(moveY);
                        }
                    }
                }
            }
            //May need to change
            gCollider.isTrigger = false;
        }
    }