Skip to content

feat: mobs play their own animations, sounds and particles while they are used - the smithy rings, sparks and steams - #578

Open
BoroBongo wants to merge 11 commits into
fix/hammer-sound-rangefrom
feature/mob-animations
Open

BoroBongo wants to merge 11 commits into
fix/hammer-sound-rangefrom
feature/mob-animations

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

Mobs now play their own state animations, with their sounds and particles, while an NPC or the hero uses them, like in the engine. In Khorinis' smithy (G2):

  • the anvil rings and throws sparks (FORGE_ANVIL, ANVIL_SPARKS);
  • the grindstone wheel turns and sparks (FORGE_SHARPEN, SHARPSTONE_SPARKS);
  • the forge flares and roars (FIRE_HOT, FORGE_FIRE);
  • the cooling bucket steams (FORGE_WATER, WATERVAPOUR).

Stoves, pans, barbecues, levers, wheels, the water pipe and the rune maker work the same way: every mob with an MDS that has T_S0_2_S1 / S_S1 / T_S1_2_S0. On the G2 world that is 12 models, baked during the load in 115 ms (editor).

The behaviour:

  • When it plays. The mob plays the transition into the user's state, loops that state, and plays the way back when the last user leaves (several NPCs can share one mob through its slots).
  • The hero. When the hero forges himself, the anvil, forge and grindstone work while his mob dialog is open. A hero's lever or wheel swings and stays in its new state.
  • What is left out. Doors, chests and beds stay as they are (the VR hinge moves them). The forge gives no extra light, like the original.
  • Cost. A mob only animates while it is used (MobAnimator turns itself off), and particle effects are built once per mob and replayed.

Technical:

  • New types. MobAnimationService (Services/Vobs) with the IMobAnimator / IMobAnimatorFactory port, and MobAnimator (Adapters/Vob), a CPU player for a mob's few rigid nodes.
  • Shared with NPCs. AnimationEffectPlayer (SFX/PFX events) and AnimationSampling are extracted from AnimationSystem / AnimationPoseJob, shared by NPCs and mobs, with no behaviour change for NPCs.
  • One release path. NpcService.ReleaseMob is now the one place an NPC lets go of a mob: AI_StandUp, death, culling, starting over. The last user's release resets the mob state, so a smith killed at the anvil leaves it free.
  • Hinge rule. IsHingeMob holds the rule now shared by the VR grab and this service.
  • New event. GlobalEventDispatcher.MobDialogEnded (the hero's mob dialog closed).
  • Docs. New Docs/mobs.md (who writes the mob state, saving, animations), plus a row in "Where does my code go?".

Stacked on #574. The sound effect code moved into AnimationEffectPlayer, which now calls #574's AudioService.GetSfxRangeMeters. Merge #574 first.

Why

Playtest (G2 Khorinis): the smithy was silent and still, with no sparks, a grindstone that didn't turn, and no forge sounds. The mobs' own MDS animations, which carry them, were never played.

How to test manually

  • G2 Khorinis smithy, 07:00-08:00 (Marvin set time). Harad moves between the forge, anvil and bucket (with fix: NPCs move on with their daily routine - a routine change ends the routine's state (Harad leaves the anvil, sleepers get up) #575). At the anvil you see sparks and hear hits; at the forge, a flare and a roar; at the bucket, steam. The editor log at load shows [MobAnimation] <model>: T_S0_2_S1, T_S1_2_S0, S_S1 per model and Animations of N mob models baked in X ms.
  • Grindstone (Carl or Brian): the wheel turns and the sparks fall (with the particle fix PR, they fall instead of streaking).
  • Walk away while Harad works: the sound fades with distance. Harad leaves: the sound stops.
  • Kill or knock out Harad at the anvil: the animation and sound stop, and the anvil is free.
  • Hero forging in VR: the anvil works while the smithing choices are open and rests when they close.
  • A lever or wheel (with a gate): it swings and stays, and the gate still opens and closes.
  • G1 Old Camp smith: the same.
  • Regression: NPC footsteps on different ground, the stab-finish sound, joint smoke on NPCs; doors, chests and beds unchanged.

Save/load

Nothing new is saved: the mob state already is (MobStatesSaveSection), and a mob's animation starts again with the next use after a load.

Known gaps / follow-ups

🤖 Generated with Claude Code

BoroBongo and others added 11 commits November 25, 2026 23:34
…ble outside AnimationSystem - no behaviour change

- AnimationEffectPlayer (Adapters/Animations) plays a track instance's *eventSFX/*eventPFX/*eventPFXStop; AnimationSystem owns one (one-off particles, as before), mobs will own one that builds each effect once and replays it
- AnimationSampling (Models/Animations, static, Burst) holds the frame interpolation and Nlerp of AnimationPoseJob
- IVirtualObject.IsHingeMob(): the door/chest rule of the VR grab (MobInteractionService.ShouldHandleGrab) in one place

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…) - no behaviour change

UseMob's last back transition, AI_StandUp(Quick) and AiHandler.ReEnableNpc cleared the mob, slot, state and body state each on their own. The mob's own animation will stop there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ads (MobAnimationService)

- MobAnimationService (Services/Vobs): which mobs animate (an oCMobInter family member with an .MDS visual - no doors, chests, beds, fireplaces), the track names of a state change (T_S0_2_S1, S_S1, T_S1_2_S0) in the mob's own model script, one-shot logs for missing models/tracks (missing tracks Editor only)
- At WorldSceneLoaded the world's mob models are baked and their sounds decoded (P3), with an Editor log of the tracks found per model
- IMobAnimator / IMobAnimatorFactory: the port the MobAnimator adapter will implement
- AnimationService.GetSkeleton also takes the hierarchy from an .MDL (hierarchy and mesh in one file), like the mesh builder

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…icles (MobAnimator) - nothing calls it yet

- MobAnimator (Adapters/Vob, added on first use by MobAnimatorFactory): maps the model's nodes once, samples the rigid nodes on the CPU (AnimationSampling), plays a transition then the state's loop, events through its own AnimationEffectPlayer (one 3D sound, linear to the event's range; particles built once and replayed); Update only while something plays
- users per mob (slots): the last one leaving lets a running transition end, plays the way back (T_S1_2_S0) and rests
- safety net once per loop round: a user that is gone, culled, dead or no longer at the mob stops it
- MobAnimationService: OnStateChanged / Stop / StartHeroUse / StopHeroUse / IsStillUsing; IMobAnimatorFactory bound in ReflexProjectInstaller

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e an NPC or the hero uses them - the smithy rings, sparks and steams

- UseMob: every transition of the user also plays the mob's own (T_S0_2_S1 then S_S1, ...)
- NpcService.ReleaseMob stops it; ReleaseMob now also runs at death (NpcDeathDomain.Die - a killed smith frees the anvil) and when a culled NPC is moved to its routine waypoint (AiHandler.DisableNpc, like ReEnableNpc: mob state -1)
- the hero: levers/wheels swing into their new state (trigger branch 0 <-> 1); a mob with a dialog (anvil, grindstone, rune table) works while its dialog is open (new GlobalEventDispatcher.MobDialogEnded, raised where DialogService drops the mob dialog anchor); without a dialog (the forge's item swap) it works once, there and back
- the safety net also stops for a knocked out user (IsDown)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bs' own animations (Docs/mobs.md, ADR)

- Docs/mobs.md: MobState writers (UseMob, AiHandler, MobInteractionService, VRMobHinge, MobStatesSaveSection), NpcService.ReleaseMob as the one end of a usage, the animation classes and data flow, the light player, follow-ups, a "where does my change go" table
- architecture.md: "Where does my code go?" row and principle 8 point to Docs/mobs.md
- ADR 2026-11-25-mob-animations: why mobs animate, the hero's smithy, no doors/chests/beds, no forge light, no switch, the own light player (not AnimationSystem per mob)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e fire no longer roars on after the smith walked away

A lever pull without a user still lets its sound play out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t user's release resets the mob state in NpcService.ReleaseMob

Wld_GetMobState then reads 0 and a save no longer keeps the anvil as used. Before, only a culled NPC reset it
(AiHandler). An NPC only walking to the mob doesn't touch its state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ared (MobInteractionService)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…en when the world is left (MobAnimationService)

A mob that isn't loaded yet gets no animator - the hero's lever pull then plays no animation, now with an Editor log.
On a world change or a loaded game the hero's mob dialog use is cleared, so it never points at a destroyed mob.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BoroBongo

Copy link
Copy Markdown
Contributor Author

Design and review

Design. Built with the design skill: plan, ADR, and an architecture-reviewer pass on the plan (fits with concerns). The plan findings were taken in before building:

  • one release path;
  • the effect player shared with NPCs;
  • particles built once and replayed;
  • several users per mob;
  • Docs/mobs.md.

Author's decisions: all used mobs except doors, chests and beds; the hero's own forging animates the mob; no extra forge light; G1+G2, VR+Flat, no flag.

Review of the build. Architecture: fits with concerns, plan followed. Gothic: no blocking bug. Fixed:

Kept on purpose: an NPC that is culled frees its mob at once.

Follow-ups: #576.

Editor check (G2 Khorinis):

  • 12 mob models baked in 115 ms at load.
  • The author confirmed in play: anvil sparks spread around, a turning grindstone, sounds and particles at the forge and the bucket.
  • No exceptions.
  • After the review fixes, the branch compiles (outside Unity) but is not yet re-run in the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant