12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using UnityEngine;
- using System.Collections;
- using RootMotion;
- namespace RootMotion.FinalIK {
- public partial class Grounding {
-
-
-
- public class Pelvis {
-
-
-
-
- public Vector3 IKOffset { get; private set; }
-
-
-
- public float heightOffset { get; private set; }
- private Grounding grounding;
- private Vector3 lastRootPosition;
- private float damperF;
- private bool initiated;
- private float lastTime;
-
- public void Initiate(Grounding grounding) {
- this.grounding = grounding;
-
- initiated = true;
- OnEnable();
- }
-
- public void Reset() {
- this.lastRootPosition = grounding.root.transform.position;
- lastTime = Time.deltaTime;
- IKOffset = Vector3.zero;
- heightOffset = 0f;
- }
-
-
- public void OnEnable() {
- if (!initiated) return;
- this.lastRootPosition = grounding.root.transform.position;
- lastTime = Time.time;
- }
-
-
- public void Process(float lowestOffset, float highestOffset, bool isGrounded) {
- if (!initiated) return;
- float deltaTime = Time.time - lastTime;
- lastTime = Time.time;
- if (deltaTime <= 0f) return;
-
- float offsetTarget = lowestOffset + highestOffset;
- if (!grounding.rootGrounded) offsetTarget = 0f;
-
-
- heightOffset = Mathf.Lerp(heightOffset, offsetTarget, deltaTime * grounding.pelvisSpeed);
-
- Vector3 rootDelta = (grounding.root.position - lastRootPosition);
- lastRootPosition = grounding.root.position;
-
-
- damperF = Interp.LerpValue(damperF, isGrounded? 1f: 0f, 1f, 10f);
-
-
- heightOffset -= grounding.GetVerticalOffset(rootDelta, Vector3.zero) * grounding.pelvisDamper * damperF;
-
- IKOffset = grounding.up * heightOffset;
- }
- }
- }
- }
|