Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
525dfda
fix: Fellan's hammering is heard from Alwin's sheep pen - the hammer …
BoroBongo Nov 25, 2026
5e903d6
refactor: animation sound/particle events and bone sampling are reusa…
BoroBongo Nov 25, 2026
f855023
refactor: an NPC's mob usage ends in one place (NpcService.ReleaseMob…
BoroBongo Nov 25, 2026
ddfbb62
feat: mob state animations are looked up and baked while the world lo…
BoroBongo Nov 25, 2026
313465c
feat: a mob can play its own state animation with its sounds and part…
BoroBongo Nov 25, 2026
ce77fa6
feat: mobs play their own state animations, sounds and particles whil…
BoroBongo Nov 25, 2026
36ec125
docs: mobs - who writes the mob state, who uses a mob, saving, the mo…
BoroBongo Nov 25, 2026
a1d6059
chore: meta files of the new mob animation scripts (generated by Unit…
BoroBongo Nov 25, 2026
7744022
fix: a mob's sound stops with it when the last user leaves - the forg…
BoroBongo Nov 25, 2026
e7054cc
fix: a smith killed or stood up at the anvil leaves it free - the las…
BoroBongo Nov 25, 2026
34923ac
docs: why the hero's mob use starts only after the mob dialog is prep…
BoroBongo Nov 25, 2026
c8eaf5c
fix: a skipped mob animation is logged, and the hero's mob is forgott…
BoroBongo Nov 26, 2026
679e961
refactor: the smoke blown out at the VR mouth takes the particle effe…
BoroBongo Nov 26, 2026
832a394
feat: the VR mouth tells a smoked part when it comes and goes and blo…
BoroBongo Nov 26, 2026
23e3ed9
feat: a water pipe's mouthpiece can be taken in VR - its hose bends t…
BoroBongo Nov 26, 2026
db6910b
feat: smoking a water pipe in VR - at the mouth it bubbles and smokes…
BoroBongo Nov 26, 2026
d96ef93
chore: meta files of the water pipe scripts (generated by Unity on im…
BoroBongo Nov 26, 2026
b1c98fa
fix: the water pipe's mouthpiece is easy to grab and smokes at the mo…
BoroBongo Nov 26, 2026
06c909b
fix: the water pipe bubbles and smokes while the mouthpiece is at the…
BoroBongo Nov 26, 2026
d9e3ac9
fix: breathing out the water pipe's smoke is heard - the joint's smok…
BoroBongo Nov 26, 2026
d24f2a9
fix: the water pipe's smoke is held for a second before it's breathed…
BoroBongo Nov 26, 2026
6d49e4d
fix: a water pipe saved while an NPC smoked it can be taken after a l…
BoroBongo Nov 26, 2026
f4d1bdb
refactor: whether an NPC uses a mob right now is decided in Core (Vob…
BoroBongo Nov 26, 2026
5f7d958
fix: a water pipe culled or unloaded at the VR mouth no longer breaks…
BoroBongo Nov 26, 2026
2e97894
fix: a water pipe's mouthpiece grabbed while an NPC smokes it (or wit…
BoroBongo Nov 26, 2026
895e6cf
fix: a water pipe's mouthpiece can be taken as soon as the NPC leaves…
BoroBongo Nov 26, 2026
8ee1124
refactor: smoking at the VR mouth is its own class (VRMouthSmoking) a…
BoroBongo Nov 26, 2026
96225c1
chore: meta file of VRMouthSmoking (generated by Unity on import)
BoroBongo Nov 26, 2026
8a17233
fix: animation sounds play at Gothic's own volume of each sound - the…
BoroBongo Nov 26, 2026
4746ca7
fix: the options' sound effects slider works - world sounds, NPC and …
BoroBongo Nov 26, 2026
46b9e74
fix: the sound effects volume slider shows in the sound options again…
BoroBongo Nov 26, 2026
efd3a8f
fix: the sound effects slider plays Gothic's own volume at 75% - the …
BoroBongo Nov 26, 2026
e4516e4
Merge pull request #581 from Gothic-Unity-Project/fix/sfx-volume
JaXt0r Nov 30, 2026
b1a444a
fix: a mob works exactly as long as an NPC or the hero uses it - who …
JaXt0r Dec 3, 2026
dded03a
fix: a smith knocked out at the anvil lets go of it like a killed one…
JaXt0r Dec 3, 2026
4bc4df4
fix: a mob whose model has no root node logs why it won't move instea…
JaXt0r Dec 3, 2026
8041949
fix: the sound effects slider works through the SoundEffects mixer gr…
JaXt0r Dec 3, 2026
1b3391b
fix: the sound effects slider defaults to 1 like Gothic - its top end…
JaXt0r Dec 3, 2026
9c736ad
fix: an NPC's animation sound effects play on an animation sound sour…
JaXt0r Dec 3, 2026
470c844
fix: ground sound events are recognised by their prefix independent o…
JaXt0r Dec 3, 2026
2044ff9
fix: an animation sound that doesn't exist no longer cuts the sound s…
JaXt0r Dec 3, 2026
239568f
fix: which sound an animation event plays (footstep by ground, Gothic…
JaXt0r Dec 3, 2026
3518fe9
fix: the hammering range override is a tuning value in Constants.Audi…
JaXt0r Dec 3, 2026
f6af5d0
fix: one place decides "visual is a model script" (ZenKitExtension.Ha…
JaXt0r Dec 3, 2026
80e7ada
fix: mob animations are baked during world loading behind the loading…
JaXt0r Dec 3, 2026
6cfd2e6
docs: ADR for the sound effects slider (Gothic's own volume, default …
JaXt0r Dec 3, 2026
745812c
fix: animation sounds carry exactly their Gothic range like in OpenGo…
JaXt0r Dec 3, 2026
5fd418f
Merge pull request #578 from Gothic-Unity-Project/feature/mob-animations
JaXt0r Dec 3, 2026
46b14d3
Merge branch 'fix/hammer-sound-range' into feature/vr-water-pipe
JaXt0r Dec 3, 2026
d513d8f
Merge pull request #580 from Gothic-Unity-Project/feature/vr-water-pipe
JaXt0r Dec 3, 2026
80790f4
docs: the sound ADR no longer tells the removed hammering override - …
JaXt0r Dec 3, 2026
58b4539
feat: DeveloperConfig.EnableImprovements switches small additions bey…
JaXt0r Dec 3, 2026
4384f04
feat: G2 improvement - Fellan's hammering carries 24 m and is heard f…
JaXt0r Dec 3, 2026
9e995d3
docs: the feature checklist says where an improvement beyond the orig…
JaXt0r Dec 3, 2026
1faa1ee
Merge remote-tracking branch 'origin/develop' into fix/hammer-sound-r…
JaXt0r Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .claude/skills/feature-checklist/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ description: Implementation checklist for new features and fixes in Gothic-Unity
the `daedalus-bridge` skill).
- **Search narrowly.** The repo is huge - never grep the project root or all of `Assets/`. Scope to e.g.
`Assets/Gothic-Core/Scripts/Services/`.
- **Beyond the original game?** A special case Gothic doesn't have (e.g. Fellan's hammering carrying 24 m) is an
*improvement*: put it in the game-version module (`Assets/Gothic2/`, via a Core `Context*Service` proxy), gate it
with `DeveloperConfig.EnableImprovements` and no active mod - never a special case in Core
(`G2SoundRangeService`).

## DeveloperConfig flags

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
PreselectGameVersion: 1
GameVersion: 0
EnableImprovements: 1
PreSelectMod: 0
ModIni:
ModPath:
Expand Down Expand Up @@ -71,6 +72,7 @@ MonoBehaviour:
SunLightIntensity: 1
SunUpdateInterval: 2
AmbientLightColor: {r: 0.10196079, g: 0.10196079, b: 0.10196079, a: 1}
EnableWorldLightmaps: 1
StartTimeHour: 8
StartTimeMinute: 0
TimeSpeedMultiplier: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
PreselectGameVersion: 0
GameVersion: 0
EnableImprovements: 1
PreSelectMod: 0
ModIni:
ModPath:
Expand Down
10 changes: 5 additions & 5 deletions Assets/Gothic-Core/Resources/Prefabs/Vobs/oCNpc.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ AudioSource:
m_GameObject: {fileID: 2815092147823170342}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
OutputAudioMixerGroup: {fileID: 6160132109742411210, guid: 118dcb5485ad4894fb619aab7e1f8708, type: 2}
m_audioClip: {fileID: 0}
m_Resource: {fileID: 0}
m_PlayOnAwake: 0
Expand Down Expand Up @@ -247,10 +247,10 @@ Rigidbody:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3647559741746323219}
serializedVersion: 4
serializedVersion: 5
m_Mass: 80
m_Drag: 0
m_AngularDrag: 0.05
m_LinearDamping: 0
m_AngularDamping: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
Expand Down Expand Up @@ -302,4 +302,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e31e900fff574068b5e83a20a4f2df42, type: 3}
m_Name:
m_EditorClassIdentifier:
_capsuleCollider: {fileID: 0}
_walkCollider: {fileID: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
using System.Collections.Generic;
using Gothic.Core.Extensions;
using Gothic.Core.Logging;
using Gothic.Core.Manager;
using Gothic.Core.Models.Animations;
using Gothic.Core.Services.Meshes;
using Reflex.Attributes;
using UnityEngine;
using ZenKit;
using Logger = Gothic.Core.Logging.Logger;
using Object = UnityEngine.Object;

namespace Gothic.Core.Adapters.Animations
{
/// <summary>
/// Plays the sound (*eventSFX) and particle (*eventPFX, *eventPFXStop) events of an animation track instance
/// whose frames were crossed this frame (AnimationTrackInstance.GetPending*). Owned by the object that plays the
/// animation: AnimationSystem (NPCs) and MobAnimator (used mobs).
///
/// Two ways to handle particles:
/// - one-off (NPCs): every event builds its effect, which destroys itself after playing (_pfxMaxSeconds at most).
/// - reusing (mobs): an effect is built on its first event and replayed on the next ones - an anvil hit twice per
/// loop rebuilt its sparks (meshes, materials) every time otherwise. DestroyAllPfx() removes them.
/// </summary>
public class AnimationEffectPlayer
{
[Inject] private readonly AudioService _audioService;
[Inject] private readonly MeshService _meshService;

// *eventPFX effects that run until their *eventPFXStop (same index). Safety: gone after this time anyway.
private const float _pfxMaxSeconds = 12f;
private const float _pfxFadeSeconds = 8f;

/// <summary>
/// An effect of the reusing mode, built once: the event it belongs to (name + bone) and its particle systems.
/// </summary>
private struct ReusedPfx
{
public string Name;
public string Bone;
public int Index;
public GameObject Root;
public ParticleSystem[] Systems;
}

private readonly Transform _boneRoot;
private readonly Transform _stepOrigin;
private readonly AudioSource _stepSound;
private readonly AudioSource _clipSound;
// The volume the clip source had: Gothic's volume of each sound is applied on top of it.
private readonly float _soundBaseVolume;
// Daedalus instance index of the NPC, -1 for a mob: a game version module may change its sound ranges.
private readonly int _npcInstanceIndex;
private readonly bool _isReusingPfx;

// One-off mode: effects with an index, until their *eventPFXStop.
private readonly Dictionary<int, GameObject> _activePfx = new();
private readonly List<int> _activePfxIndices = new();

// Reusing mode: every effect built so far.
private readonly List<ReusedPfx> _reusedPfx = new();


/// <param name="boneRoot">The bones of *eventPFX are searched below it; effects without a bone start at it.
/// </param>
/// <param name="stepOrigin">Where a step sound (*eventSFXGrnd) asks for the ground below.</param>
/// <param name="stepSound">Plays the step sounds as one-shots on top of everything else. An NPC's NpcSound
/// (shared with hits, weapon draws, ...).</param>
/// <param name="clipSound">Plays the *eventSFX clips, one at a time like the engine's model sound. Needs an own
/// source: a clip's volume (Gothic's of each sound) and range would turn down the one-shots of a shared source.
/// Mobs pass their single source for both.</param>
/// <param name="npcInstanceIndex">Daedalus instance index of the NPC playing the animations, -1 for a mob.
/// </param>
/// <param name="isReusingPfx">Build each effect once and replay it (mobs), see class summary.</param>
public AnimationEffectPlayer(Transform boneRoot, Transform stepOrigin, AudioSource stepSound,
AudioSource clipSound, int npcInstanceIndex, bool isReusingPfx)
{
_boneRoot = boneRoot;
_stepOrigin = stepOrigin;
_stepSound = stepSound;
_clipSound = clipSound;
_soundBaseVolume = clipSound != null ? clipSound.volume : 1f;
_npcInstanceIndex = npcInstanceIndex;
_isReusingPfx = isReusingPfx;
}

/// <summary>
/// Plays the sounds whose frame was crossed. Returns true if there were any (also skipped footsteps).
/// </summary>
public bool ApplySfxEvents(AnimationTrackInstance trackInstance)
{
var sfxEvents = trackInstance.GetPendingSoundEffects();
if (sfxEvents == null)
return false;

foreach (var sfx in sfxEvents)
{
// What to play (footstep by the ground below, Gothic's volume and range) is AudioService's decision.
// No clip (footsteps off, missing or nosound): nothing changes, a clip still playing on the source
// (a fire loop) keeps playing.
var toPlay = _audioService.GetAnimationSfx(_npcInstanceIndex, sfx.Name, sfx.Range.ToMeter(),
_stepOrigin.position);
if (toPlay.Clip == null)
continue;

// A step plays on top of the other sounds (it mustn't cut a swing or a scream).
if (toPlay.IsStep)
{
_stepSound.PlayOneShot(toPlay.Clip, toPlay.Volume);
continue;
}

// Gothic's volume of the sound (Forge_Sharpen 40 of 127). The player's sound effects slider works
// through the source's mixer group (AudioService.SoundEffectsGroup). One clip at a time.
_clipSound.clip = toPlay.Clip;
_clipSound.volume = _soundBaseVolume * toPlay.Volume;
_clipSound.maxDistance = toPlay.RangeMeters;
_clipSound.Play();
}

return sfxEvents.Count > 0;
}

/// <summary>
/// *eventPFX (frame, index, name, bone, ATTACH) creates the effect at the
/// bone (following it if attached), *eventPFXStop (frame, index) lets it fade out. Joint smoke, bubbles, ...
/// </summary>
public void ApplyPfxEvents(AnimationTrackInstance trackInstance)
{
var stops = trackInstance.GetPendingParticleEffectStops();
if (stops != null)
{
foreach (var stop in stops)
StopPfx(stop.Index);
}

var pfxEvents = trackInstance.GetPendingParticleEffects();
if (pfxEvents == null)
return;

foreach (var pfx in pfxEvents)
{
if (_isReusingPfx && TryReplayPfx(pfx))
continue;

var root = CreatePfx(pfx, trackInstance.AnimationName);
if (root == null)
continue;

if (_isReusingPfx)
{
_reusedPfx.Add(new ReusedPfx
{
Name = pfx.Name,
Bone = pfx.Position,
Index = pfx.Index,
Root = root,
Systems = root.GetComponentsInChildren<ParticleSystem>()
});
continue;
}

if (pfx.Index != 0)
{
StopPfx(pfx.Index);
_activePfx[pfx.Index] = root;
_activePfxIndices.Add(pfx.Index);
}
Object.Destroy(root, _pfxMaxSeconds);
}
}

/// <summary>
/// Builds the effect of a *eventPFX. Returns its root (the effect and its sub emitters), null if it failed.
/// </summary>
private GameObject CreatePfx(IEventParticleEffect pfx, string animationName)
{
var bone = FindBone(pfx.Position) ?? _boneRoot;
// A reused effect lives as long as the animator: it must not destroy itself after its first play.
var isDestroyedAfterPlay = !_isReusingPfx;
var pfxGo = pfx.Attached
? _meshService.CreateVobPfx(pfx.Name, parent: bone.gameObject, destroyAfterPlay: isDestroyedAfterPlay)
: _meshService.CreateVobPfx(pfx.Name, bone.position, bone.rotation,
destroyAfterPlay: isDestroyedAfterPlay);
if (pfxGo == null)
{
Logger.LogWarning($"[AnimationPfx] {pfx.Name} couldn't be created ({animationName}).",
LogCat.Animation);
return null;
}

var parent = pfxGo.transform.parent;
var root = parent != null && parent != bone ? parent.gameObject : pfxGo;
foreach (var particleSystem in root.GetComponentsInChildren<ParticleSystem>())
{
var main = particleSystem.main;
main.simulationSpace = ParticleSystemSimulationSpace.World;
}

// A mob's effect stays with the mob (culled with it, destroyed with the world).
if (_isReusingPfx && !pfx.Attached)
root.transform.SetParent(_boneRoot, true);

return root;
}

/// <summary>
/// Reusing mode: the effect of this event was built before - it starts again. Stopping its emission first
/// restarts a burst that is still running (the second anvil hit), its particles in the air stay.
/// </summary>
private bool TryReplayPfx(IEventParticleEffect pfx)
{
for (var i = 0; i < _reusedPfx.Count; i++)
{
var reused = _reusedPfx[i];
if (reused.Root == null || !reused.Name.EqualsIgnoreCase(pfx.Name) ||
!reused.Bone.EqualsIgnoreCase(pfx.Position))
continue;

foreach (var particleSystem in reused.Systems)
{
if (particleSystem == null)
continue;
particleSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting);
particleSystem.Play(false);
}
return true;
}

return false;
}

private void StopPfx(int index)
{
if (_isReusingPfx)
{
// Reusing mode: the effect only stops emitting, the next event of its index starts it again.
for (var i = 0; i < _reusedPfx.Count; i++)
{
if (_reusedPfx[i].Index == index)
StopEmitting(_reusedPfx[i].Systems);
}
return;
}

if (!_activePfx.Remove(index, out var pfxGo))
return;
_activePfxIndices.Remove(index);
if (pfxGo == null)
return;

foreach (var particleSystem in pfxGo.GetComponentsInChildren<ParticleSystem>())
particleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting);
Object.Destroy(pfxGo, _pfxFadeSeconds);
}

/// <summary>
/// Every effect running until its *eventPFXStop fades out now (one-off mode). In reusing mode all effects stop
/// emitting and are destroyed once their particles faded.
/// </summary>
public void StopAllPfx()
{
if (_isReusingPfx)
{
foreach (var reused in _reusedPfx)
{
StopEmitting(reused.Systems);
if (reused.Root != null)
Object.Destroy(reused.Root, _pfxFadeSeconds);
}
_reusedPfx.Clear();
return;
}

// Backwards: StopPfx removes the index from the list.
for (var i = _activePfxIndices.Count - 1; i >= 0; i--)
StopPfx(_activePfxIndices[i]);
}

private static void StopEmitting(ParticleSystem[] systems)
{
foreach (var particleSystem in systems)
{
if (particleSystem != null)
particleSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting);
}
}

/// <summary>
/// MDS bone names differ in case from the bone GameObjects ("Bip01 Head" vs "BIP01 HEAD").
/// </summary>
private Transform FindBone(string boneName)
{
if (string.IsNullOrEmpty(boneName))
return null;
foreach (var child in _boneRoot.GetComponentsInChildren<Transform>())
{
if (child.name.EqualsIgnoreCase(boneName))
return child;
}
return null;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading