Skip to content

Commit

Permalink
Make head tilts smooth
Browse files Browse the repository at this point in the history
  • Loading branch information
Sauceke committed Nov 6, 2023
1 parent bd51a01 commit 19f2fc1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions KK_SexFaces/ChaControlExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections;
using UnityEngine;

namespace SexFaces
{
public static class ChaControlExtensions
{
public static void MoveNeck(this ChaControl chaControl, Quaternion end)
=> chaControl.StartCoroutine(SlerpNeck(chaControl, end));

private static IEnumerator SlerpNeck(ChaControl chaControl, Quaternion end)
{
const float durationSecs = 1f;
float startTime = Time.unscaledTime;
var start = Hooks.NeckLookCalcHooks.GetNeckRotation(chaControl);
while (Time.unscaledTime - startTime < durationSecs)
{
var t = (Time.unscaledTime - startTime) / durationSecs;
t = 1f - (1f - t) * (1f - t);
var rotation = Quaternion.Slerp(start, end, t);
Hooks.NeckLookCalcHooks.SetNeckRotation(chaControl, rotation);
yield return new WaitForEndOfFrame();
}
}
}
}
2 changes: 1 addition & 1 deletion KK_SexFaces/FacialExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Apply(ChaControl chaControl)
}
chaControl.mouthCtrl.ChangeFace(StringToDict(MouthExpression), true);
chaControl.ChangeMouthOpenMax(MouthOpenMax);
Hooks.NeckLookCalcHooks.SetNeckRotation(chaControl, NeckRot ?? Quaternion.identity);
chaControl.MoveNeck(NeckRot ?? Quaternion.identity);
}

private static bool IsLookingAtFixedPosition(ChaControl chaControl)
Expand Down

0 comments on commit 19f2fc1

Please sign in to comment.