top of page

Card game
​

Skills: Shader Graph & Custom Shaders, Animation
Tools: Unity 

​Overview

Exploring something a bit different this time—default Unity card UI can feel super stiff, but it's an easy fix. Decoupling card logic from visuals while adding smooth physics and tilt makes the cards feel weightless, responsive, and fun to interact with.

​

Technical Breakdown 

The Big Idea: Decouple Logic from Visuals

If you move a card directly to a slot, it instantly snaps into place and looks stiff.

Instead, split every card into two objects:

  1. The Target (Logic) ➡️ An invisible marker that instantly teleports where the card should be (e.g., in a hand or slot).

  2. The Visual (Graphics) ➡️ The actual card artwork. It constantly glides toward the Target with physics, tilt, and scaling.

​​

Step 1: Create the Visual Movement Script

Attach this script (CardVisual.cs) to your visible card object (Sprite or Canvas UI Image).

​

​

​

✅How This Script Helps

  • Smooth Glide: Vector3.Lerp creates a fluid movement instead of instant snapping.

  • Dynamic Tilt: Calculating currentVelocity allows the card to lean into turns when moved horizontally, creating aerodynamic drag.

​

Step 2: Create the Hand Layout Script

Attach this script (CardHand.cs) to an empty parent object in your scene to automatically arrange cards in a curved fan shape.

​

​

​

✅How This Script Helps

  • Automatic Spacing: Recalculates card positions dynamically whenever a card is drawn or played.

  • Curved Arc: Uses basic math (Mathf.Pow) to dip outer cards downward and tilt them outward.

​

Step 3: Scene Setup Checklist

  1. Create an empty object named HandContainer and add the CardHand component.

  2. For each card in your hand:

    • Create an empty GameObject named CardSlot_1 as a child of HandContainer.

    • Create a separate GameObject named CardVisual_1 with your card image and add CardVisual.cs.

    • Assign CardSlot_1 into the Target Transform field on CardVisual_1.

  3. Drag all your CardSlot objects into the Card Slots list on the CardHand script.

Move any CardSlot in your scene, and the visual card will follow with physics tilt and movement juice.

bottom of page