MadreDeDios

LD 43

2D Physics in a 3D Context: My First Card Game!

It was very fun for me to create my first ever card game in Unity!

wheel.jpg

It was also the first time I used 2D Physics in a 3D context!
Which if you didn't know, is completely possible in Unity and can be very useful in a Jam context. The 2D physics being much easier to setup and use, it was the perfect solution for a card game.

Unityem2018-12-04/em12-02-31.png

However, this caused one major change: The 2D colliders will only be working in the XY axis, no matter the rotation of the object it seats on. So, the card being flat on the table means their 2D collider cannot work straight away!

Easy enough to fix, I put everything under a parent object including lights and cameras, and rotated that object 90 degrees!

Unityem2018-12-04/em12-00-07.jpg

Luckily I didn't have to use the skybox nor the gravity...

Perspectives in a Card Game

I wanted to avoid creating 2D digital designs for the table and the background of my game (I'm no artist...). So I've decided to make it 3D.

I wasn't convinced by the look of an orthographic camera so I went with a narrow FOV perspective camera. Unityem2018-12-04/em12-28-06.png

But now that my cards are 3D objects, how can I make sure they don't intersect with the table when flipping? Unityem2018-12-04/em12-31-10.png

I used two cameras for that: Unityem2018-12-04/em12-32-45.png After setting the environment on a separate layer, I simply had to set the first camera's Culling Mask to the Environment layer only, and its Depth to 0. The main camera has the Environment excluded from its Culling Mask, Clear Flags to Depth Only and its Depth to 1!

WebGL
When porting to WebGL, it was no longer possible to handle that feature. The number of cameras being limited to one, the environment wasn't rendering.
So I had a more traditional camera sitting in the scene, and if I detect the platform to be WebGL, I just turn this camera on and the others off!

Unityem2018-12-04/em12-39-27.png