Designing Immersion

with Game Engines

Music Box Movement Simulation

Individual coursework for DDES9912 Designing Immersion with Game Engines.

Instructor: Bradley Lin

⇲ Music Box Movement Simulation

Simulation Object Reference:

Powerhouse Museum Object Link:
https://collection.powerhouse.com.au/object/237165

Repository Link:
https://github.com/flyBacon/DDES9912_MusicBox

Object in Assets\Scenes\MusicBoxPlayground.unity

⇲ Movement Mechanism

Based on the Powerhouse Museum description, its physical appearance, and various textual and video references of comparable antique cylinder music boxes, this particular movement could be identified as a full orchestral type, equipped with:

• a drum with 8 beaters
• 38-note regular pitched comb
• 14-note reed organ
• 6 bells
• a castanet with 6 beaters

1. The actual movement is powered by a mainspring, a coiled strip of tempered steel housed within a spring barrel.  When the user winds the lever (rotational input), the elastic potential energy is stored in the tightened mainspring.

2. As the mainspring unwinds, stored energy is released as rotational motion and transmitted through a set of reduction gears, which drives the cylinder (pinned barrel), including multiple bevel gears to change the axis of rotation.

3. Without regulation, the mainspring would unwind rapidly, resulting in uncontrolled playback speed. This is stabilized by a centrifugal governor, which operates through air resistance: as rotational speed increases, drag forces rise nonlinearly, limiting further acceleration. This creates a quasi-stable rotational velocity, ensuring consistent musical timing.


Considering playability, the Unity simulation could provide two input methods:
- winding lever mode: constant note triggering speed; mimic the actual movement.
- hand crank mode: fully react to user’s real-time input, variable direction and speed.

↳ engineerguy. (2015, December 8). How a wind up music box works [Video]. YouTube. https://www.youtube.com/watch?v=COty6_oDEkk

The cylinder then drives multiple sound-producing elements in parallel:

• Pitched comb
Pins pluck tuned steel teeth, which vibrate at specific frequencies to produce melodic tones.

• Unpitched Comb (drum, bells, castanet)
Pins actuate trigger combs and lever mechanisms, which store and release mechanical energy to drive hammers striking membranes or metal elements.

• Reed Organ Levers
Staples engage valve levers, opening air passages connected to a bellows-driven wind supply. Airflow excites free reeds, generating sustained tones.

↳ engineerguy. (2015, December 8).
How a wind up music box works [Video]. YouTube. https://www.youtube.com/watch?v=COty6_oDEkk

↳ Vincent Freeman Antiques. (n.d.). Antique Piece a Oiseau Full Orchestral Antique Music Box by Ami Rivenc, c. 1870.

https://www.vincentfreemanantiques.com/cylinder-music-box/ami-rivenc-4

⇲ Interaction Flow

⇲ Modeling in Blender

⇲ Music Score Preprocess and Procedural Workflow

Currently, the first selected musical piece is ‘近未來 (Near Future)’ by 蘇打綠 sodagreen, and the score is retrieved from: https://yudans.net/196/近未來-琴譜

The score was largely reduced and adapted to a constrained 38-note range (D3 to E♭6), corresponding to the bones P0–P37, which are bound to the pitched comb geometry.

Using an open-source Houdini package for importing .musicxml (https://github.com/MarnSchokker/houdini-musicxml), along with custom nodes and scripts, the melody pins were procedurally generated. In addition, via Houdini, the data were exported as a .csv file containing angular position and note index values, essentially converting the musical score into a text asset readable by Unity. This approach eliminates the need for pin-based triggering within the simulation.

Further development could involve extending this pipeline to replicate the full orchestration of the movement, including drum, bells, reed organ, and castanet components.

⇲ Custom Scripts

Every bone in the armature has the Pluck.cs script component. Once loaded in the scene, the corresponding audio sample with the same file name will be loaded automatically.

When a comb finger is plucked, it plays its audio clip and starts an animation coroutine, which interpolates its local rotation to the target value across multiple frames within the set duration.

Attached to the movement object root, Sequencer.cs reads the exported .csv score as discrete pin events
(angle in degrees + note index).

Every frame, it retrieves the cylinder’s rotation and triggers individual comb fingers when the cylinder passes each event angle.

To avoid Euler angle flips when the local x-axis rotation of the cylinder lies in [90, 270], which would trigger wrong bones, it computes the delta rotation using quaternion, extracts the signed angle, and accumulates this into a phase value (0–360°), which determines the passed angular interval.

 As the user may spin the cylinder in arbitrary directions, these Trigger functions will determine whether the rotation was forward or backward, and whether the angle has passed 0/360°; and then call PluckOnce() on all matching bones within the note event range, in order.

⇲ Player Hand Interaction

In my Assessment 1 scene, the simulation was quite rough. It only used a fixed camera view, and the cylinder rotation was controlled through keyboard input. 

For Assessment 2, the first thing I considered was how to create an interaction method that felt interesting, simple to understand, and XR-like. Inspired by the VR game Half-Life: Alyx, though I have never played it, I decided to create a floating right hand in front of the first-person camera. When the hand moves close to an interactable element, it enters a preparation pose. When the player clicks the mouse, the interaction is triggered.

I found the hand rig on Sketchfab: “First Person hands rigged” by David Fischer, licensed under Creative Commons Attribution. I modified the rig and created several animations myself, including idle, prepare, prepare idle, wind lever interaction, and play lever on/off interactions.

For the music box movement itself, I improved the modelling and materials. Since the reference images from the Powerhouse Museum were not detailed enough, I also studied many similar antique music box movements from www.vincentfreemanantiques.com to better understand how the mechanism works. To recreate a more authentic operating experience, the player now interacts with the music box through two levers. All linked gears are update()-ed together via the revised CylinderSpin.cs script.

⇲ Interaction Scripts and Animators

HandInteractionAnimator.cs is attached to the HandAnchor transform under the MainCamera. The script checks the distance between the hand and two interaction anchors on the music box: the winding lever anchor and the play lever anchor. The closest anchor determines the current interaction type. This distance is continuously passed to the hand Animator Controller through the DistanceToInteractableStuff float parameter, which drives the hand’s preparation state machine.

When the player presses the interaction input, the script first checks whether the hand is within the allowed interaction distance. It then stores the current interaction type, preventing the target from changing while the hand is moving. This avoids accidentally triggering a different lever when the hand passes closer to another anchor during the animation.

Both the hand Animator Controller and the Music Box Animator Controller use the same parameters: an interactionType integer and an Interact trigger. The value 1 triggers winding, 2 triggers play-lever-on, and 3 triggers play-lever-off. This keeps the hand motion and the mechanical music box animation synchronized.

During interaction, the hand anchor is temporarily detached from its camera parent. It smoothly moves to the shared music box transform using interpolation, remains there while the animation plays, then returns to its original local position and rotation under the camera. This prevents the hand from drifting with player’s movement during interaction.

The script also includes commented-out hooks for NPC shoulder tapping. This feature was planned but not completed due to time constraints.

⇲ NPC Interaction

A rigged humanoid model from my previous work is used for NPCs, along with some manually created interaction animations and 4 retargeted mixamo animations. WanderMusicBoxUser.cs is attached to each NPC. They uses a NavMeshAgent to wander around the baked NavMesh. It randomly chooses points within a radius around a wander center, waits for a random idle duration, and occasionally attempts to use the music box.

Before using the music box, the NPC calls TryClaim() on MusicBoxNPCCoordinator. This coordinator prevents two NPCs from using the music box at the same time. If the claim succeeds, the NPC walks to the predefined NPCUsePoint.

Because the interaction animations were created in Blender with the armature origin aligned to the NPCUsePoint (local position relative to the music box transform), the NPC root is locked exactly to NPCUsePoint during the interaction. The script disables NavMeshAgent position and rotation updates, aligns the character, and repeatedly enforces the locked transform in LateUpdate. This prevents unwanted offsets from navigation or animation blending.

Once aligned, the NPC performs fixed sequences. First, it triggers the NPC wind animation, triggers the corresponding music box animation with interactionType = 1, and calls NPCWind() through the coordinator. Then, if the play lever is currently off, it triggers the NPC play-lever-on animation, triggers the music box animation with interactionType = 2, and calls NPCSetPlayLeverOn().

After the sequence, the NPC releases the coordinator claim, unlocks its root transform, re-enables NavMeshAgent updates, and walks to NPCLeavePoint before returning to wandering.

⇢The End

⇢Tom's Journal

⇢Apr 2026

⇢swipe or scroll⇢