From 6f1517a34b2f8bc0bed60e36b434811c5866fb9c Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 19 Jan 2022 14:40:57 +0100 Subject: [PATCH] First nullpointer bug when no head bone is present in certain cases --- Runtime/HumanoidFree/Scripts/Targets/HeadTarget.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Runtime/HumanoidFree/Scripts/Targets/HeadTarget.cs b/Runtime/HumanoidFree/Scripts/Targets/HeadTarget.cs index 9b56d0f..9034598 100644 --- a/Runtime/HumanoidFree/Scripts/Targets/HeadTarget.cs +++ b/Runtime/HumanoidFree/Scripts/Targets/HeadTarget.cs @@ -1130,7 +1130,12 @@ namespace Passer.Humanoid { // With ChangeAvatar, the bone may be at a different height than wat setup in the scene // Therfore we need to use the target here // I don't understand myself here. Using bone again - Vector3 worldHeadEyeDelta = eyePosition - head.bone.transform.position; + Vector3 worldHeadEyeDelta; + if (neck.bone.transform != null) + worldHeadEyeDelta = eyePosition - head.bone.transform.position; + else + worldHeadEyeDelta = eyePosition - head.target.transform.position; + Vector3 localHeadEyeDelta = Quaternion.AngleAxis(-head.target.transform.eulerAngles.y, Vector3.up) * worldHeadEyeDelta; return localHeadEyeDelta; }