Skip to content

Ibrahim-Abdelqader/3D-Heart-puzzle-game

Repository files navigation

3D Heart puzzle game


video.mp4

Overview

A 3D heart puzzle game created using unity and blender to help students figure out the heart parts making it fun and usefull at the same time.


Table of contents


Blender process

firstly we have to choses the right model to process it on blender using its features. I'm going to put the right steps I took to generate a Mesh-Divided heart model

  1. Import the right model

    • you can build a heart model in belnder or just select it from any library on google
    • open blender and import your model
  2. Select the knife

    • start cutting off your heart model into multiple pieces

    • don't move the parts away, keep them united. you will need them as one unit in unity

    • make the edges smooth and seamless (you can search to find the right way)

  3. Exprot your model

    • after finishing the whole work on blender, export you file into .fbx

    • keep your model in a safe place


Unity process

after preparing our model in blender, we will pass it to Unity to build our puzzle game. But before going on the core game, we have just to build a frindly GUI for the user. Here we go:

GUI

  1. Create a Canvas (Your Screen’s “Drawing Board”)

    • In Unity’s Hierarchy window: → Right-click → UI → Canvas. This is where all your buttons/text/images will live.
  2. Add UI Elements (Buttons, Text, etc.)

    • For a button: → Right-click on the Canvas → UI → Button. → A Text object will auto-appear inside it. Click the button to rename the text (e.g., “Start Game”).

    • For text: → Right-click on the Canvas → UI → Text. → Type your message in the Text field (e.g., “Score: 0”).

  3. Adjust Size & Position

    • Select your UI element (button/text) in the Hierarchy.

    • In the Inspector window: → Use the Rect Transform tool (the blue rectangle) to drag and resize it. → Or type exact numbers for Pos X, Pos Y, Width, and Height.

  4. Make It Look Nice (Optional)

    • Change colors/fonts: → Select the UI element → In the Inspector, tweak:

      • Text Color, Font Style (for text).

      • Source Image (for custom button graphics).

  5. Make Buttons DO Something

    • Create a new C# script (e.g., MenuManager.cs): → In Unity: Assets → Create → C# Script. → Double-click to open it in your code editor.

    • Add this code to the script:

         using UnityEngine;  
         using UnityEngine.UI;  // Required for UI
         
         public class MenuManager : MonoBehaviour {
             public Button yourButtonName; // Assign in Unity Inspector
      
             void Start() {
                 // Make the button call a function when clicked
                 yourButtonName.onClick.AddListener(YourFunction);
             }
         
             void YourFunction() {
                 Debug.Log("Button clicked!"); 
                 // Add your action here (e.g., load a scene)
             }
         }
    • Link the script to your button: → Drag the script onto the Canvas or any GameObject. → Select the script in the Inspector → Drag your button into the yourButtonName slot.

  6. Test It!

    • Press Play in Unity.

    • Click the button to see your message in the Console (or trigger your action).

Core game

after creating the GUI let's build the core game. we have to include the modle in unity. Our work is divided into 5 principles including: camera, drag & drop, snap, randomize and Timer. let's talk about each one of them:

1. Camera

Role in Your Game:

The camera is how players view and interact with the heart pieces. Since it’s a 3D puzzle, you’ll want players to see the heart from angles that make solving intuitive.

How to Use It:
  • Isometric View: Set the camera at a 45-degree angle to show all heart pieces clearly (like a chessboard view).

  • Zoom & Rotate: Let players rotate the heart or zoom in/out to inspect pieces (e.g., for intricate ventricle or atrium parts).

  • Focus on Selected Piece: When a player clicks a piece, smoothly move the camera closer to it.

2. Drag & Drop

Role in Your Game:

Players need to drag heart pieces and place them correctly. This mechanic is the core of your puzzle!

How to Use It:
  • 3D Dragging: Use OnMouseDrag() or raycasting to let players click and drag pieces.

  • Visual Feedback: Highlight a piece when hovered (e.g., glow) to show it’s interactable.

3. Snap

Role in Your Game:

When players place a heart piece near its correct spot, it should “snap” into place for a satisfying fit.

How to Use It:
  • Proximity Check: If a piece is close to its target position, snap it.

  • Rotation Alignment: Ensure the piece’s rotation matches the target (e.g., a ventricle fragment aligns with the heart’s chambers).

    SNAP.gif

4. Randomize

Role in Your Game:

Shuffle the heart pieces at the start of each level to create fresh challenges.

How to Use It:
  • Random Positions: Spawn pieces in random locations around the heart.
  • Random Rotations: Rotate pieces randomly to increase difficulty.

5. Timer

Role in Your Game:

Add urgency! Players must solve the puzzle before time runs out (e.g., a "heartbeat" timer).

How to Use It:
  • Countdown UI: Display a timer bar or numeric counter.
  • Penalty/Reward: Lose time for wrong moves, gain time for correct snaps.

Quick Preview

1. Model segmentation

knif tool heart parts

2. GUI desing

GUI

3. camera, drag & drop, snap, randomize, timer

core1 code core2


Submitted to:

  • Dr. Tamer Basha All rights reserved © 2024 - Systems & Biomedical Engineering, Cairo University (Class 2028)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published