2D Game - Change Perspective from Orthographic to Perspective

Hi All,

I’m working on a 2D tile based game. I am able to move the tiles/chips around as normal, but now feel that having the world ‘appear’ 3D would look better.

What would be the best approach to make the world appear 3D while still constraining the movement to the current 2D plane?

        if (Input.GetMouseButtonDown(0)) {
            Vector2 point = controlCamera.ScreenPointToRay(Input.mousePosition).origin;
            hit = Physics2D.Raycast(point, Vector2.zero);
            if (!hit.transform) return;
            pressedChip = hit.transform.GetComponent<Chip>();
            pressPoint = Input.mousePosition;
        }
        if (Input.GetMouseButton(0) && pressedChip != null) {
            Vector2 move = Input.mousePosition;
            move -= pressPoint;
            if (move.magnitude > Screen.height * 0.05f) {
                foreach (Side side in Utils.straightSides)
                    if (Vector2.Angle(move, Utils.SideOffsetX(side) * Vector2.right + Utils.SideOffsetY(side) * Vector2.up) <= 45)
                        pressedChip.Swap(side);
                pressedChip = null;
            }
        }

  public Chip GetChipFromTouch() {
     Vector2 point;
     if (isMobilePlatform) {
       if (Input.touchCount == 0) return null;
       point = controlCamera.ScreenPointToRay(Input.GetTouch(0).position).origin;
     } else
       point = controlCamera.ScreenPointToRay(Input.mousePosition).origin;
     
     hit = Physics2D.Raycast(point, Vector2.zero);
     if (!hit.transform) return null;
     return hit.transform.GetComponent<Chip>();
   }

I’ve looked into this further, it appears that a 2.5D is the approach I want to take.

I’ve changed the camera perspective to Perspective. Though now the mouse clicks are out of synch and they are not activating the right tiles/chips.

Any suggestions?

Hi

Apologies for bumping this again.

Having a difficult time converting this to accept Vector3 as opposed to Vector2, any help would be very greatly appreciated.

What would be the best way to insert Vector3 functions but still preserve the 2D mechanics of the games?

Thanks

You could look at some of the 2.5d assets in the asset store, they might help

Thanks though it’s difficult to find an asset that incorporates similar functions of the above.

I will try using Vector3 raycast to obtain the clicks,
how about the segment of code below as it is Vector2 do I need to convert the Vector3 readings to Vector2?

You see I want the 2D game mechanics to work as normal and just change the way the mouse clicks are recognised.

if (move.magnitude > Screen.height * 0.05f) {
              foreach (Side side in Utils.straightSides)
                  if (Vector2.Angle(move, Utils.SideOffsetX(side) * Vector2.right + Utils.SideOffsetY(side) * Vector2.up) <= 45)
                      pressedChip.Swap(side);
              pressedChip = null;
          }