예제 #1
0
파일: Entity2D.cs 프로젝트: Volpanic/Nova
    /// <summary>
    /// Same as moveX but in y position
    /// </summary>
    /// <param name="amount"></param>
    public void MoveY(float amount) // IN UNITS
    {
        subPixelVelocity.y += amount;
        float move = Mathf.Round(subPixelVelocity.y * PIXEL_SIZE) / PIXEL_SIZE; // In Units

        if (move != 0)
        {
            subPixelVelocity.y -= move;
            float sign = Mathf.Sign(move * PIXEL_SIZE) / PIXEL_SIZE;

            while (move != 0)
            {
                if (!Physics2DExtra.PlaceMeeting(ref bCollider, new Vector2(0, sign), groundLayer))
                {
                    transform.position += new Vector3(0, sign, 0);
                    Physics2D.SyncTransforms();
                    move -= sign;
                }
                else
                {
                    velocity.y         = 0;
                    subPixelVelocity.y = 0;
                    break;
                }
            }
        }
        Physics2D.SyncTransforms();
    }
예제 #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;
        }
    }
예제 #3
0
파일: Entity2D.cs 프로젝트: Volpanic/Nova
 private bool OnGround()
 {
     return(Physics2DExtra.PlaceMeeting(ref bCollider, new Vector2(0, -1 * Physics2DExtra.PIXEL_UNIT), groundLayer));
 }
예제 #4
0
파일: Entity2D.cs 프로젝트: Volpanic/Nova
 /// <summary>
 /// Returns if a entity is ontop of a collider
 /// </summary>
 /// <param name="collider"></param>
 /// <returns></returns>
 public bool IsRiding(ref Collider2D collider)
 {
     return(Physics2DExtra.PlaceMeeting(bCollider, new Vector2(0, -1 * Physics2DExtra.PIXEL_UNIT), groundLayer, collider));
 }