fix(fenrir): the Cultist's flames leave its mouth

The breath effect was placed 1.5 m above the player's feet and 1 m
ahead, chest height on a Cultist and the same whatever the form's size.

It now sits on the form's Jaw bone (fenring_cultist rig: Neck/Head/Jaw,
read from the game files), 0.3 m ahead, Head as the second choice and
the old fixed point if neither exists. A small follower places it every
LateUpdate, facing where the player faces, on the owner's copy and on
every onlooker's. The burn area is unchanged.
This commit is contained in:
kanym 2026-10-29 02:30:05 +01:00
commit 3dae107b85

View file

@ -323,7 +323,8 @@ namespace RacesOfValheim
GameObject fireVfx = ZNetScene.instance.GetPrefab("fx_fenring_flames");
if (fireVfx == null) return null;
GameObject instance = Object.Instantiate(fireVfx, player.transform.position + Vector3.up * 1.5f + player.transform.forward, player.transform.rotation, player.transform);
GameObject instance = Object.Instantiate(fireVfx, MouthPoint(player), player.transform.rotation, player.transform);
instance.AddComponent<CultistFlameFollow>().Player = player;
// Aumentiamo la durata delle particelle del 20%
foreach (ParticleSystem ps in instance.GetComponentsInChildren<ParticleSystem>())
@ -334,6 +335,41 @@ namespace RacesOfValheim
return instance;
}
// Bone names the breath leaves from, mouth first. Matched by name anywhere under the form.
private static readonly string[] MouthBones = { "Jaw", "Head" };
/// <summary>
/// Where the Cultist's breath starts: just ahead of the form's jaw (or head), so it leaves the
/// mouth at whatever size the form stands. It used to be a fixed 1.5 m above the player's
/// feet, chest height on a Cultist, which is the "fire starts too low" report. Falls back on
/// that fixed point if the form has neither bone.
/// </summary>
public static Vector3 MouthPoint(Player player) => MouthPoint(player, FindMouth(player));
public static Vector3 MouthPoint(Player player, Transform bone)
{
Transform body = player.transform;
return bone != null
? bone.position + body.forward * 0.3f
: body.position + Vector3.up * 1.5f + body.forward;
}
public static Transform FindMouth(Player player)
{
foreach (string wanted in MouthBones)
{
foreach (Transform child in player.transform)
{
if (child.name == "Visual" || !child.gameObject.activeInHierarchy) continue;
foreach (Transform t in child.GetComponentsInChildren<Transform>())
{
if (string.Equals(t.name, wanted, System.StringComparison.OrdinalIgnoreCase)) return t;
}
}
}
return null;
}
public static void PublishFire(bool on)
{
Player player = Player.m_localPlayer;
@ -1665,4 +1701,31 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Keeps the Cultist's breath at its mouth: on the Jaw bone (fenring_cultist rig:
/// .../Neck/Head/Jaw), facing where the player faces. Placed every LateUpdate, after the form's
/// Animator has moved the head, rather than parented to the bone, so the flames point where the
/// player aims and not wherever the jaw happens to tilt. The same on every client's copy.
/// </summary>
internal class CultistFlameFollow : MonoBehaviour
{
public Player Player;
private Transform mouth;
private float nextLook;
private void LateUpdate()
{
if (Player == null) return;
// The form can be rebuilt under the same flames; look again now and then if lost.
if (mouth == null && Time.time >= nextLook)
{
nextLook = Time.time + 0.5f;
mouth = FenrirAttackSync.FindMouth(Player);
}
transform.SetPositionAndRotation(FenrirAttackSync.MouthPoint(Player, mouth), Player.transform.rotation);
}
}
}