]> git.cameronkatri.com Git - gmtk-gamejam.git/commitdiff
Smooth leg animation
authorCarson Katri <carson.katri@gmail.com>
Sat, 12 Jun 2021 19:09:04 +0000 (15:09 -0400)
committerCarson Katri <carson.katri@gmail.com>
Sat, 12 Jun 2021 19:09:04 +0000 (15:09 -0400)
Assets/Scripts/Controllers/Player/PlayerController.cs

index 3674d92cc22c67a8720dd317f60f77eee0333adb..e67358c6854b7650d76ffcdbf52b13559b3db11f 100644 (file)
@@ -51,10 +51,16 @@ namespace Controllers.Player
         {
           if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode))
           {
         {
           if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode))
           {
-            segment.left.leg.transform.localRotation =
-              Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * legSpeed));
-            segment.right.leg.transform.localRotation =
-              Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * -legSpeed));
+            segment.left.leg.transform.localRotation = Quaternion.Slerp(
+              segment.left.leg.transform.localRotation,
+              Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * legSpeed * (segment.Rigidbody.velocity.magnitude / 5f))),
+              Time.deltaTime * 50f
+            );
+            segment.right.leg.transform.localRotation = Quaternion.Slerp(
+              segment.right.leg.transform.localRotation,
+              Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * -legSpeed * (segment.Rigidbody.velocity.magnitude / 5f))),
+              Time.deltaTime * 50f
+            );
           }
           else
           {
           }
           else
           {