fix(skeleton): reattach the mandible, light the skull for real, and grow at Fader

The jaw hung off the side of the skull because a creature rig carries bones a
human rig has no answer for. Unmatched bones fell back to bones[0] - the root -
so the mandible was skinned to the hips and followed them. The remap now walks
the creature'''s own hierarchy upward until something matches, which lands a jaw on
the head. It no longer opens, which no player will notice, and it is attached,
which every player did. Teeth and any other facial part the model carries are
fixed by the same walk.

The head flame never appeared. It was built by hand out of the smoke material
with a hand-rolled fire gradient, which at best would have read as a wisp rather
than a burning skull, and at worst never resolved a source at all and returned in
silence. It now clones real fire particles off a vanilla prefab - the torch
first, ground torches and the fire pit behind it - and says in the log which one
it took, or warns if none of them resolved. The torch light comes with it, at
half range and reduced intensity, since a light tuned to fill a corridor from
waist height blows out a face at point-blank range.

Fader now stands 15% taller. That scale goes on the player root, which is how
this race has always sized itself, so the collider, the camera pivot and every
equipment attachment scale with the mesh rather than leaving the model to drift
away from them.
This commit is contained in:
kanym 2026-08-05 17:30:15 +02:00
commit 59c250b4f8
3 changed files with 110 additions and 57 deletions

View file

@ -62,6 +62,46 @@ namespace RacesOfValheim
// Above the head bone's own origin, which sits at the base of the skull.
private const float HeadFlameHeight = 0.18f;
// Torch flames are authored for a fist-sized fire on a stick. This is the two knobs to
// turn if the skull ends up wearing a bonfire or a birthday candle.
private const float HeadFlameScale = 1.8f;
// Fire sources in preference order. The torch is an item every world has; the ground
// torch and the fire pit are the building pieces to fall back on.
private static readonly string[] FlameSourcePrefabs =
{
"Torch", "piece_groundtorch_wood", "piece_groundtorch", "fire_pit"
};
private static GameObject cachedFlameSource;
private static bool flameSourceResolved;
/// <summary>
/// Finds a vanilla prefab that carries real fire particles. Resolved once per session,
/// failure included, so a miss cannot turn into a per-frame log.
/// </summary>
private static GameObject ResolveFlameSource()
{
if (flameSourceResolved) return cachedFlameSource;
flameSourceResolved = true;
foreach (string name in FlameSourcePrefabs)
{
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(name);
if (prefab == null) continue;
if (prefab.GetComponentsInChildren<ParticleSystem>(true).Length == 0) continue;
Jotunn.Logger.LogInfo($"[Skeleton] Head flame source resolved to '{name}'.");
cachedFlameSource = prefab;
return cachedFlameSource;
}
Jotunn.Logger.LogWarning(
"[Skeleton] No fire prefab resolved (" + string.Join(", ", FlameSourcePrefabs) +
"); the skull stays unlit.");
return null;
}
private static List<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
private List<ItemDrop.ItemData> GetBestRealFoods(int state)
@ -408,65 +448,47 @@ namespace RacesOfValheim
headFlameBone = anim != null ? anim.GetBoneTransform(HumanBodyBones.Head) : null;
if (headFlameBone == null) return; // rig not up yet; try again next frame
GameObject sourceVFX = PrefabManager.Cache.GetPrefab<GameObject>("vfx_smoke") ??
PrefabManager.Cache.GetPrefab<GameObject>("vfx_surtling_death");
ParticleSystemRenderer sourceRenderer =
sourceVFX != null ? sourceVFX.GetComponentInChildren<ParticleSystemRenderer>() : null;
if (sourceRenderer == null) return;
GameObject source = ResolveFlameSource();
if (source == null) return; // already logged once by the resolver
headFlameVFX = new GameObject("SkeletonHeadFlameVFX");
headFlameVFX.transform.SetParent(Player.m_localPlayer.transform, false);
headFlameVFX.transform.localScale = Vector3.one * HeadFlameScale;
ParticleSystem ps = headFlameVFX.AddComponent<ParticleSystem>();
// Real fire is cloned rather than built by hand. The first attempt at this made a
// particle system from scratch on the smoke material, and a hand-rolled gradient
// over a smoke sprite reads as a wisp, not a burning skull.
foreach (ParticleSystem ps in source.GetComponentsInChildren<ParticleSystem>(true))
{
GameObject copy = Instantiate(ps.gameObject, headFlameVFX.transform);
copy.name = ps.gameObject.name;
copy.transform.localPosition = Vector3.zero;
copy.transform.localRotation = Quaternion.identity;
copy.SetActive(true);
var main = ps.main;
main.loop = true;
main.duration = 1f;
main.startLifetime = new ParticleSystem.MinMaxCurve(0.35f, 0.6f);
main.startSize = new ParticleSystem.MinMaxCurve(0.18f, 0.38f);
main.startSpeed = new ParticleSystem.MinMaxCurve(0.4f, 0.9f);
main.simulationSpace = ParticleSystemSimulationSpace.World;
// So the holder's scale actually enlarges the fire rather than just spreading
// out where the particles spawn.
ParticleSystem.MainModule main = copy.GetComponent<ParticleSystem>().main;
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
}
headFlameVFX.GetComponent<ParticleSystemRenderer>().material = sourceRenderer.material;
// A torch's own light is tuned to light a corridor from waist height; on a head it
// blows out the whole face. Keep the glow, lose the floodlight.
foreach (Light light in headFlameVFX.GetComponentsInChildren<Light>(true))
{
light.range *= 0.5f;
light.intensity *= 0.6f;
}
var shape = ps.shape;
shape.shapeType = ParticleSystemShapeType.Sphere;
shape.radius = 0.11f;
var emission = ps.emission;
emission.rateOverTime = 28f;
// Straight up, so it reads as burning rather than drifting.
var velocity = ps.velocityOverLifetime;
velocity.enabled = true;
velocity.space = ParticleSystemSimulationSpace.World;
velocity.y = new ParticleSystem.MinMaxCurve(0.5f);
var colorOverLifetime = ps.colorOverLifetime;
colorOverLifetime.enabled = true;
Gradient grad = new Gradient();
grad.SetKeys(
new GradientColorKey[]
{
new GradientColorKey(new Color(1f, 0.95f, 0.55f), 0.0f), // pale yellow core
new GradientColorKey(new Color(1f, 0.45f, 0.05f), 0.45f), // orange
new GradientColorKey(new Color(0.35f, 0.05f, 0.0f), 1.0f) // ember, guttering out
},
new GradientAlphaKey[]
{
new GradientAlphaKey(0.0f, 0.0f),
new GradientAlphaKey(0.8f, 0.15f),
new GradientAlphaKey(0.5f, 0.7f),
new GradientAlphaKey(0.0f, 1.0f)
}
);
colorOverLifetime.color = grad;
// Tapers as it rises, the way a flame narrows toward its tip.
var sizeOverLifetime = ps.sizeOverLifetime;
sizeOverLifetime.enabled = true;
sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(
1f, new AnimationCurve(new Keyframe(0f, 0.6f), new Keyframe(0.3f, 1f), new Keyframe(1f, 0.15f)));
// Anything that made the source a torch rather than a fire.
foreach (MonoBehaviour comp in headFlameVFX.GetComponentsInChildren<MonoBehaviour>(true))
{
Destroy(comp);
}
foreach (Collider col in headFlameVFX.GetComponentsInChildren<Collider>(true))
{
Destroy(col);
}
}
if (!headFlameVFX.activeSelf) headFlameVFX.SetActive(true);