From f326fdea96c2c7d479f25baef5a4a70ec6ce4fa8 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Wed, 25 Nov 2026 23:16:25 +0000 Subject: [PATCH 1/4] fix: sparks, smoke and spell particles fall and drift in the world - they no longer move or turn with their emitter Particles simulated in the emitter's space unless dirFor was WORLD, and flyGravity was applied in that space too. A turned emitter (the grindstone's wheel, a spell in the hand) pulled its particles sideways into a line instead of a falling shower. Like the engine, an emitted particle now lives in the world and gravity points down; dirFor/shpFor still give the frame a particle starts in. Tried live in the editor (G2 Khorinis smithy): the grindstone sparks fall. Co-Authored-By: Claude Opus 5.5 --- .../Domain/Meshes/Builder/VobPfxMeshBuilder.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs index 946aa346a..7bc6c486d 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs @@ -215,12 +215,10 @@ public override GameObject Build() // Always disable Unity's built-in gravity - use Force over Lifetime instead mainModule.gravityModifier = 0f; - // Simulation space from FOR switches (prefer dir FOR if present) - var simFor = (pfx.DirForS ?? pfx.ShpForS)?.ToUpperInvariant(); - if (simFor == "WORLD") - mainModule.simulationSpace = ParticleSystemSimulationSpace.World; - else - mainModule.simulationSpace = ParticleSystemSimulationSpace.Local; + // Like the engine, an emitted particle lives in the world: it doesn't move or turn with its emitter + // afterwards. dirFor/shpFor only say in which frame a particle starts (velocity module below). Local + // simulation carried the sparks along with the turning grindstone - a line instead of a falling shower. + mainModule.simulationSpace = ParticleSystemSimulationSpace.World; // Start size from visSizeStart (cm->m). Allow end scale via Size over Lifetime below. if (!string.IsNullOrEmpty(pfx.VisSizeStartS) && pfx.VisSizeStartS != "=") @@ -287,6 +285,9 @@ public override GameObject Build() if (gravity.Length == 3) { forceModule.enabled = true; + // flyGravity is a world vector (down is -Y): in the emitter's frame a turned emitter (a grindstone, + // a spell in the hand) pulled its particles sideways. + forceModule.space = ParticleSystemSimulationSpace.World; forceModule.x = gravityX; forceModule.y = gravityY; forceModule.z = gravityZ; From 2f969f5253af28d65337cad7ca5fb7db9d4d162b Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Wed, 25 Nov 2026 23:37:16 +0000 Subject: [PATCH 2/4] fix: the glow of a spell held in the ring or a slot stays with the hand instead of smearing into a streak PrepareHeldEffect only set Local simulation for Gothic's own motion; the ring's and the slot's standing glow relied on the builder's old default (Local). The builder now simulates in World, so that glow was left behind in the world when the hand moved. Both modes simulate in the hand's space now. Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs index c5f32f4ff..0732d981a 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs @@ -79,11 +79,12 @@ public static void PrepareHeldEffect(GameObject effect, bool isGothicMotion) main.loop = true; // Default (Local) ignores the parent's scale - the invest level size and the ring's fit wouldn't show. main.scalingMode = ParticleSystemScalingMode.Hierarchy; + // Moving with the hand/ring, not left behind in the world - in both modes (the builder simulates in + // World: the ring's standing glow smeared into a streak when the hand moved). + main.simulationSpace = ParticleSystemSimulationSpace.Local; var emission = ps.emission; if (isGothicMotion) { - // Moving with the hand/ring, not left behind in the world. - main.simulationSpace = ParticleSystemSimulationSpace.Local; if (emission.rateOverTime.constantMax < _minEmissionRate) emission.rateOverTime = _minEmissionRate; } From b1b7ad58d93ed64daad2daa5c8baf13aa5964e09 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Thu, 26 Nov 2026 19:25:22 +0000 Subject: [PATCH 3/4] fix: a spell's glow in an NPC's or the hero's hand, auras and effects on an NPC move with him instead of trailing Since particles live in the world, effects stuck to a moving body were left behind: a mage's hand glow streaked behind his arm, the sleep effect over the head and hit effects on an NPC trailed when he walked, the light spell's glow trailed behind the hero. CreateVobPfx(isFollowingEmitter) builds them in the emitter's space again (also their sub-emitters). The VR hand charge and the ring/slot effects pass it too. A swung torch flame and flying spells stay in the world (they trail like in Gothic). Co-Authored-By: Claude Opus 5.5 --- .../Domain/Meshes/Builder/VobPfxMeshBuilder.cs | 18 ++++++++++++++++-- .../Actions/AnimationActions/AiDrawWeapon.cs | 10 +++++++--- .../Scripts/Services/Meshes/MeshService.cs | 4 +++- .../Scripts/Services/Meshes/ParticleService.cs | 4 +++- .../Scripts/Adapters/Player/VRSpellEffect.cs | 3 ++- .../Scripts/Adapters/Vob/VobItem/VRSpellFx.cs | 12 +++++++----- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs index 7bc6c486d..502d26096 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs @@ -99,7 +99,8 @@ private void CreateSubEmitter(ZenKit.Daedalus.ParticleEffectInstance pfx, GameOb _subEmitterDepth++; try { - var child = _pfxMeshService.CreateVobPfx(childName, parent: pfxGo, destroyAfterPlay: _destroyAfterPlay); + var child = _pfxMeshService.CreateVobPfx(childName, parent: pfxGo, destroyAfterPlay: _destroyAfterPlay, + isFollowingEmitter: _isFollowingEmitter); var childRoot = child != null ? child.transform.parent : null; if (childRoot != null && childRoot.gameObject != pfxGo) childRoot.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); @@ -132,6 +133,7 @@ private void CreateSubEmitter(ZenKit.Daedalus.ParticleEffectInstance pfx, GameOb private string _visualName; private bool _destroyAfterPlay; + private bool _isFollowingEmitter; public void SetPfxData(string visualName) @@ -144,6 +146,15 @@ public void SetDestroyAfterPlay(bool destroyAfterPlay) _destroyAfterPlay = destroyAfterPlay; } + /// + /// An effect that sticks to a moving body (a spell's glow in a hand, an aura on an NPC): its particles move and + /// turn with the emitter (Local simulation). Otherwise they live in the world once emitted. + /// + public void SetFollowingEmitter(bool isFollowingEmitter) + { + _isFollowingEmitter = isFollowingEmitter; + } + /// /// Spell/visual effects: looping ones emit their full ppsValue (the /100 was tuned for world fires). /// @@ -218,7 +229,10 @@ public override GameObject Build() // Like the engine, an emitted particle lives in the world: it doesn't move or turn with its emitter // afterwards. dirFor/shpFor only say in which frame a particle starts (velocity module below). Local // simulation carried the sparks along with the turning grindstone - a line instead of a falling shower. - mainModule.simulationSpace = ParticleSystemSimulationSpace.World; + // Effects stuck to a moving body (a glow in a hand, an aura) move with it (SetFollowingEmitter). + mainModule.simulationSpace = _isFollowingEmitter + ? ParticleSystemSimulationSpace.Local + : ParticleSystemSimulationSpace.World; // Start size from visSizeStart (cm->m). Allow end scale via Size over Lifetime below. if (!string.IsNullOrEmpty(pfx.VisSizeStartS) && pfx.VisSizeStartS != "=") diff --git a/Assets/Gothic-Core/Scripts/Domain/Npc/Actions/AnimationActions/AiDrawWeapon.cs b/Assets/Gothic-Core/Scripts/Domain/Npc/Actions/AnimationActions/AiDrawWeapon.cs index b4eab5fd7..942721541 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Npc/Actions/AnimationActions/AiDrawWeapon.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Npc/Actions/AnimationActions/AiDrawWeapon.cs @@ -113,16 +113,20 @@ private void SpawnSpellVfx() if (NpcContainer.ActiveSpellVfxGo != null) Object.Destroy(NpcContainer.ActiveSpellVfxGo); var pfxName = $"MFX_{mfxName.ToUpper()}_INIT"; - NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo); + // The glow stays in the hand (follows the emitter) - in the world it streaked behind the mage's arm. + NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo, + isFollowingEmitter: true); if (NpcContainer.ActiveSpellVfxGo == null) { pfxName = "MFX_FIREBALL_INIT"; // G2 fire fallback - NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo); + NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo, + isFollowingEmitter: true); } if (NpcContainer.ActiveSpellVfxGo == null) { pfxName = "MFX_FIREBOLT_INIT"; // G1 fire fallback - NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo); + NpcContainer.ActiveSpellVfxGo = _meshService.CreateVobPfx(pfxName, parent: handGo, + isFollowingEmitter: true); } // Force looping so the glow stays on hand until undraw/attack diff --git a/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs b/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs index 96562553f..228e944a4 100644 --- a/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Meshes/MeshService.cs @@ -211,10 +211,12 @@ public GameObject CreateVobPfx(IVirtualObject vob, Vector3 position = default, Q } public GameObject CreateVobPfx(string pfxName, Vector3 position = default, Quaternion rotation = default, - GameObject parent = null, bool destroyAfterPlay = false, bool isFullRate = false) + GameObject parent = null, bool destroyAfterPlay = false, bool isFullRate = false, + bool isFollowingEmitter = false) { var vobPfxBuilder = new VobPfxMeshBuilder().Inject(); vobPfxBuilder.SetFullRate(isFullRate); + vobPfxBuilder.SetFollowingEmitter(isFollowingEmitter); vobPfxBuilder.SetGameObject(null, pfxName); vobPfxBuilder.SetParent(parent); vobPfxBuilder.SetRootPosAndRot(position, rotation); diff --git a/Assets/Gothic-Core/Scripts/Services/Meshes/ParticleService.cs b/Assets/Gothic-Core/Scripts/Services/Meshes/ParticleService.cs index 296c62b1e..7401bde50 100644 --- a/Assets/Gothic-Core/Scripts/Services/Meshes/ParticleService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Meshes/ParticleService.cs @@ -90,8 +90,10 @@ private void PlayVisualFx(string fxName, Vector3 position, Transform follow, boo anchor.transform.SetPositionAndRotation(position, Quaternion.identity); if (follow != null) anchor.transform.SetParent(follow, true); + // An effect that follows someone (sleep over the head, an aura, the hit effect on an NPC) moves with + // him - in the world it trailed behind a walking NPC. var pfxGo = _meshService.CreateVobPfx(fx.VisNameS, parent: anchor, destroyAfterPlay: !isLooping, - isFullRate: true); + isFullRate: true, isFollowingEmitter: follow != null); if (pfxGo == null) { UnityEngine.Object.Destroy(anchor); diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs index 0732d981a..60579b3de 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRSpellEffect.cs @@ -40,7 +40,8 @@ public static GameObject Create(ItemInstance item, GameObject parent, DaedalusVm { if (string.IsNullOrEmpty(pfxName)) continue; - var leaf = meshService.CreateVobPfx(pfxName, parent: parent); + // Held in the hand or the ring: follows it (PrepareHeldEffect). + var leaf = meshService.CreateVobPfx(pfxName, parent: parent, isFollowingEmitter: true); if (leaf == null) continue; diff --git a/Assets/Gothic-VR/Scripts/Adapters/Vob/VobItem/VRSpellFx.cs b/Assets/Gothic-VR/Scripts/Adapters/Vob/VobItem/VRSpellFx.cs index ba14a048c..6ef730ab4 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Vob/VobItem/VRSpellFx.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Vob/VobItem/VRSpellFx.cs @@ -144,7 +144,8 @@ public void SpawnHandVfx(VrHandSide handSide, string pfxNameOverride = null) return; } var pfxName = pfxNameOverride ?? $"MFX_{mfxName.ToUpper()}_INIT"; - var pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo); + // The charge stays in the hand (follows the emitter, PrepareHeldEffect below). + var pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo, isFollowingEmitter: true); // The spell's own VISUALFX visual before the generic fallbacks: MFX_ICEWAVE_INIT doesn't exist, // spellFX_Icewave uses MFX_IceCUBE_INIT (a fireball was shown in the hand). if (pfxLeaf == null && pfxNameOverride == null) @@ -162,7 +163,7 @@ public void SpawnHandVfx(VrHandSide handSide, string pfxNameOverride = null) if (string.IsNullOrEmpty(visName)) continue; pfxName = visName; - pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo); + pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo, isFollowingEmitter: true); if (pfxLeaf != null) break; } @@ -170,12 +171,12 @@ public void SpawnHandVfx(VrHandSide handSide, string pfxNameOverride = null) if (pfxLeaf == null) { pfxName = "MFX_FIREBALL_INIT"; - pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo); + pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo, isFollowingEmitter: true); } if (pfxLeaf == null) { pfxName = "MFX_FIREBOLT_INIT"; - pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo); + pfxLeaf = _meshService.CreateVobPfx(pfxName, parent: handGo, isFollowingEmitter: true); } if (pfxLeaf != null) @@ -522,7 +523,8 @@ public void ToggleLightSpell() _stationaryLightsService.ClaimHeroLight(lightGo); stationaryLight.Init(); - _meshService.CreateVobPfx("MFX_LIGHT_INIT", parent: lightGo); + // The light's glow moves with the hero - in the world it trailed behind him. + _meshService.CreateVobPfx("MFX_LIGHT_INIT", parent: lightGo, isFollowingEmitter: true); hero.ActiveLightGo = lightGo; Logger.Log("[VRSpellFx] Light spell ON", LogCat.VR); From f1ddece461013a944bc78ceee3efc96d186015a3 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Thu, 26 Nov 2026 19:26:16 +0000 Subject: [PATCH 4/4] fix: particles of a turning emitter fly straight - their flight direction is taken into the world once, when built With World simulation Unity turns a Local velocity over lifetime with the emitter's current rotation every frame, so a turning emitter (the grindstone) still curved particles that were already flying (dirMode DIR with dirFor OBJECT, and TARGET). The direction is now converted with the emitter's rotation at creation and the velocity module is World; dirFor still says in which frame a particle starts. The root is placed before that, so the rotation is the final one. Limitation (comment): an emitter that turns after it was built keeps its first direction. Effects that follow their emitter keep the Local velocity, turning with it like before. Co-Authored-By: Claude Opus 5.5 --- .../Meshes/Builder/VobPfxMeshBuilder.cs | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs index 502d26096..f8e6f11d4 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs @@ -34,6 +34,8 @@ private void ApplyGothicShapeAndDirection(ZenKit.Daedalus.ParticleEffectInstance if (pfx.DirModeS.EqualsIgnoreCase("DIR")) { + var toVelocitySpace = GetVelocityRotation(pfx.DirForS.EqualsIgnoreCase("WORLD"), pfxGo, + out var velocitySpace); var minSpeed = Mathf.Max(0f, (pfx.VelAvg - pfx.VelVar) * _velocityScale); var maxSpeed = Mathf.Max(0f, (pfx.VelAvg + pfx.VelVar) * _velocityScale); var min = Vector3.positiveInfinity; @@ -45,8 +47,8 @@ private void ApplyGothicShapeAndDirection(ZenKit.Daedalus.ParticleEffectInstance var heading = (pfx.DirAngleHead + headStep * pfx.DirAngleHeadVar) * Mathf.Deg2Rad; var elevation = Mathf.Clamp(pfx.DirAngleElev + elevStep * pfx.DirAngleElevVar, -90f, 90f) * Mathf.Deg2Rad; - var sample = new Vector3(Mathf.Cos(elevation) * Mathf.Sin(heading), Mathf.Sin(elevation), - Mathf.Cos(elevation) * Mathf.Cos(heading)); + var sample = toVelocitySpace * new Vector3(Mathf.Cos(elevation) * Mathf.Sin(heading), + Mathf.Sin(elevation), Mathf.Cos(elevation) * Mathf.Cos(heading)); foreach (var speed in new[] { minSpeed, maxSpeed }) { min = Vector3.Min(min, sample * speed); @@ -59,9 +61,7 @@ private void ApplyGothicShapeAndDirection(ZenKit.Daedalus.ParticleEffectInstance main.startSpeed = 0f; var velocity = particleSystem.velocityOverLifetime; velocity.enabled = true; - velocity.space = pfx.DirForS.EqualsIgnoreCase("WORLD") - ? ParticleSystemSimulationSpace.World - : ParticleSystemSimulationSpace.Local; + velocity.space = velocitySpace; velocity.x = new ParticleSystem.MinMaxCurve(min.x, max.x); velocity.y = new ParticleSystem.MinMaxCurve(min.y, max.y); velocity.z = new ParticleSystem.MinMaxCurve(min.z, max.z); @@ -80,6 +80,27 @@ private void ApplyGothicShapeAndDirection(ZenKit.Daedalus.ParticleEffectInstance Convert.ToBoolean(pfx.ShpScaleIsLooping), Convert.ToBoolean(pfx.ShpScaleIsSmooth)); } + /// + /// The space of the velocity module and the rotation that takes a direction there from its frame (the world or + /// the emitter). With World simulation a Local velocity is turned with the emitter's current rotation every + /// frame - a turning emitter (the grindstone) curved particles that are already flying. So the direction is + /// taken into the world once, with the emitter's rotation at creation (dirFor OBJECT: the frame a particle + /// starts in). Limitation: an emitter that turns after it was built (reparented, a turning mover, a swung + /// torch) keeps the direction it had then - Unity has no per-particle frame for velocity over lifetime. + /// Effects that follow their emitter keep both Local (the direction turns with it, like before). + /// + private Quaternion GetVelocityRotation(bool isWorldDir, GameObject pfxGo, + out ParticleSystemSimulationSpace space) + { + if (_isFollowingEmitter) + { + space = isWorldDir ? ParticleSystemSimulationSpace.World : ParticleSystemSimulationSpace.Local; + return Quaternion.identity; + } + space = ParticleSystemSimulationSpace.World; + return isWorldDir ? Quaternion.identity : pfxGo.transform.rotation; + } + private const float _velocityScale = 10f; // VELO particles slower than this (m/s) are plain billboards. private const float _minStretchSpeed = 0.1f; @@ -512,6 +533,12 @@ public override GameObject Build() shapeModule.alignToDirection = false; // Don't align to direction for blood splatter } + // Only a requested position. Quaternion's == / != compare by dot product (default != default is true) - + // Equals() compares the components. Before the velocity: it takes the emitter's rotation into the world. + var hasRotation = !RootRotation.Equals(default(Quaternion)); + if (RootPosition != Vector3.zero || hasRotation) + RootGo.transform.SetPositionAndRotation(RootPosition, hasRotation ? RootRotation : Quaternion.identity); + ApplyGothicShapeAndDirection(pfx, particleSystem, pfxGo); // Velocity over Lifetime module (for directional spread and TARGET) @@ -536,12 +563,15 @@ public override GameObject Build() { var target = new Vector3(tx / 100f, ty / 100f, tz / 100f); var origin = Vector3.zero; // assuming emitter origin in Local space by default - var dir = (target - origin).normalized; + // The target is in the emitter's frame (as before) - into the world with the emitter's + // rotation at creation (GetVelocityRotation). + var toVelocitySpace = GetVelocityRotation(false, pfxGo, out var velocitySpace); + var dir = toVelocitySpace * (target - origin).normalized; // Use average speed var speed = Mathf.Max(0f, pfx.VelAvg); velocityModule.enabled = true; - velocityModule.space = ParticleSystemSimulationSpace.Local; + velocityModule.space = velocitySpace; velocityModule.x = new ParticleSystem.MinMaxCurve(dir.x * speed); velocityModule.y = new ParticleSystem.MinMaxCurve(dir.y * speed); velocityModule.z = new ParticleSystem.MinMaxCurve(dir.z * speed); @@ -604,12 +634,6 @@ public override GameObject Build() } } - // Only a requested position. Quaternion's == / != compare by dot product (default != default is true) - - // Equals() compares the components. - var hasRotation = !RootRotation.Equals(default(Quaternion)); - if (RootPosition != Vector3.zero || hasRotation) - RootGo.transform.SetPositionAndRotation(RootPosition, hasRotation ? RootRotation : Quaternion.identity); - particleSystem.Play(); CreateSubEmitter(pfx, pfxGo);