Advertisement
athos_k

Untitled

Oct 25th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. void LerpIKHands_Direct()
  2. {
  3. if (enableRootMovement)
  4. _ikT += Time.deltaTime * 5;
  5.  
  6. if (_ikT > 1)
  7. {
  8. _ikT = 1;
  9. ikLandSideReached = true;
  10. }
  11.  
  12. Vector3 lhPosition = Vector3.LerpUnclamped(_ikStartPos[0], _ikTargetPos[0], _ikT);
  13. ik.UpdateTargetPosition(AvatarIKGoal.LeftHand, lhPosition);
  14.  
  15. Vector3 rhPosition = Vector3.LerpUnclamped(_ikStartPos[2], _ikTargetPos[2], _ikT);
  16. ik.UpdateTargetPosition(AvatarIKGoal.RightHand, rhPosition);
  17. }
  18.  
  19. void LerpIKFeet_Direct()
  20. {
  21. if (targetPoint.pointType == PointType.hanging)
  22. {
  23. ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
  24. ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
  25. }
  26. else
  27. {
  28. if (enableRootMovement)
  29. _fikT += Time.deltaTime * 5;
  30.  
  31. if (_fikT > 1)
  32. {
  33. _fikT = 1;
  34. ikFollowSideReached = true;
  35. }
  36.  
  37. Vector3 lfPosition = Vector3.LerpUnclamped(_ikStartPos[1], _ikTargetPos[1], _fikT);
  38. ik.UpdateTargetPosition(AvatarIKGoal.LeftFoot, lfPosition);
  39.  
  40. Vector3 rfPosition = Vector3.LerpUnclamped(_ikStartPos[3], _ikTargetPos[3], _fikT);
  41. ik.UpdateTargetPosition(AvatarIKGoal.RightFoot, rfPosition);
  42. }
  43. }
  44.  
  45. void LerpIKLandingSide_Direct()
  46. {
  47. if (enableRootMovement)
  48. _ikT += Time.deltaTime * 3.2f;
  49.  
  50. if (_ikT > 1)
  51. {
  52. _ikT = 1;
  53. ikLandSideReached = true;
  54. }
  55.  
  56. Vector3 landPosition = Vector3.LerpUnclamped(_ikStartPos[0], _ikTargetPos[0], _ikT);
  57. ik.UpdateTargetPosition(ik_L, landPosition);
  58.  
  59. if (targetPoint.pointType == PointType.hanging)
  60. {
  61. ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
  62. ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
  63. }
  64. else
  65. {
  66. Vector3 followPosition = Vector3.LerpUnclamped(_ikStartPos[1], _ikTargetPos[1], _ikT);
  67. ik.UpdateTargetPosition(ik_F, followPosition);
  68. }
  69. }
  70.  
  71. void LerpIKFollowSide_Direct()
  72. {
  73. if (enableRootMovement)
  74. _fikT += Time.deltaTime * 2.6f;
  75.  
  76. if (_fikT > 1)
  77. {
  78. _fikT = 1;
  79. ikFollowSideReached = true;
  80. }
  81.  
  82. Vector3 landPosition = Vector3.LerpUnclamped(_ikStartPos[2], _ikTargetPos[2], _fikT);
  83. ik.UpdateTargetPosition(ik.ReturnOppositeIK(ik_L), landPosition);
  84.  
  85. if (targetPoint.pointType == PointType.hanging)
  86. {
  87. ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
  88. ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
  89. }
  90. else
  91. {
  92.  
  93. Vector3 followPosition = Vector3.LerpUnclamped(_ikStartPos[3], _ikTargetPos[3], _fikT);
  94. ik.UpdateTargetPosition(ik.ReturnOppositeIK(ik_F), followPosition);
  95. }
  96. }
  97.  
  98. AvatarIKGoal ik_L; //ik for the landing side
  99. AvatarIKGoal ik_F; //ik for the following side
  100. float _ikT;
  101. float _fikT;
  102. Vector3[] _ikStartPos = new Vector3[4];
  103. Vector3[] _ikTargetPos = new Vector3[4];
  104.  
  105. void InitIK(Vector3 directionToPoint, bool opposite)
  106. {
  107. Vector3 relativeDirection = transform.InverseTransformDirection(directionToPoint);
  108.  
  109. if (Mathf.Abs(relativeDirection.y) > 0.5f)
  110. {
  111. float targetAnim = 0;
  112.  
  113. if (targetState == ClimbStates.onPoint)
  114. {
  115. ik_L = ik.ReturnOppositeIK(ik_L);
  116. }
  117. else
  118. {
  119. if (Mathf.Abs(relativeDirection.x) > 0)
  120. {
  121. if (relativeDirection.x < 0)
  122. ik_L = AvatarIKGoal.LeftHand;
  123. else
  124. ik_L = AvatarIKGoal.RightHand;
  125. }
  126.  
  127. targetAnim = (ik_L == AvatarIKGoal.RightHand) ? 1 : 0;
  128. if (relativeDirection.y < 0)
  129. targetAnim = (ik_L == AvatarIKGoal.RightHand) ? 0 : 1;
  130.  
  131. anim.SetFloat("Movement", targetAnim);
  132. }
  133.  
  134. }
  135. else
  136. {
  137. ik_L = (relativeDirection.x < 0) ? AvatarIKGoal.LeftHand : AvatarIKGoal.RightHand;
  138.  
  139. if (opposite)
  140. {
  141. ik_L = ik.ReturnOppositeIK(ik_L);
  142. }
  143.  
  144. }
  145.  
  146. _ikT = 0;
  147. UpdateIKTarget(0, ik_L, targetPoint);
  148.  
  149. ik_F = ik.ReturnOppositeLimb(ik_L);
  150. _fikT = 0;
  151. UpdateIKTarget(1, ik_F, targetPoint);
  152. }
  153.  
  154. void InitIK_Direct(Vector3 directionToPoint)
  155. {
  156. if (directionToPoint.y != 0)
  157. {
  158. _fikT = 0;
  159. _ikT = 0;
  160.  
  161. UpdateIKTarget(0, AvatarIKGoal.LeftHand, targetPoint);
  162. UpdateIKTarget(1, AvatarIKGoal.LeftFoot, targetPoint);
  163.  
  164. UpdateIKTarget(2, AvatarIKGoal.RightHand, targetPoint);
  165. UpdateIKTarget(3, AvatarIKGoal.RightFoot, targetPoint);
  166. }
  167. else
  168. {
  169. InitIK(directionToPoint, false);
  170. InitIKOpposite();
  171. }
  172. }
  173.  
  174. void InitIKOpposite()
  175. {
  176. UpdateIKTarget(2, ik.ReturnOppositeIK(ik_L), targetPoint);
  177. UpdateIKTarget(3, ik.ReturnOppositeIK(ik_F), targetPoint);
  178. }
  179.  
  180. void UpdateIKTarget(int posIndex, AvatarIKGoal _ikGoal, Point tp)
  181. {
  182. _ikStartPos[posIndex] = ik.ReturnCurrentPointPosition(_ikGoal);
  183. _ikTargetPos[posIndex] = tp.ReturnIK(_ikGoal).target.transform.position;
  184. ik.UpdatePoint(_ikGoal, tp);
  185. }
  186.  
  187. void HandleWeightAll(float t, AnimationCurve aCurve)
  188. {
  189. float inf = aCurve.Evaluate(t);
  190. ik.AddWeightInfluenceAll(1 - inf);
  191.  
  192. //close the ik for the feet if going from hanging to braced
  193. if (curPoint.pointType == PointType.hanging && targetPoint.pointType == PointType.braced)
  194. {
  195. float inf2 = a_zeroToOne.Evaluate(t);
  196.  
  197. ik.InfluenceWeight(AvatarIKGoal.LeftFoot, inf2);
  198. ik.InfluenceWeight(AvatarIKGoal.RightFoot, inf2);
  199. }
  200.  
  201. if(curPoint.pointType == PointType.hanging && targetPoint.pointType == PointType.hanging)
  202. {
  203. ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
  204. ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement