Advertisement
shadowx320

AnimatorHook.cs

May 25th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace SA
  6. {
  7. public class AnimatorHook : MonoBehaviour
  8. {
  9.  
  10. Animator anim;
  11. StateManager states;
  12.  
  13. public float rm_multi;
  14. public bool rolling;
  15. float roll_t;
  16.  
  17. public void Init(StateManager st)
  18. {
  19. states = st;
  20. anim = states.anim;
  21. }
  22.  
  23. public void InitForRoll()
  24. {
  25. rolling = true;
  26. roll_t = 0;
  27. }
  28.  
  29. public void CloseRoll()
  30. {
  31. if(rolling == false)
  32. return;
  33.  
  34. rm_multi = 1;
  35. roll_t = 0;
  36. rolling = false;
  37. }
  38.  
  39. void OnAnimatorMove()
  40. {
  41. if (states.canMove)
  42. return;
  43.  
  44. states.rigid.drag = 0;
  45.  
  46. if (rm_multi == 0)
  47. rm_multi = 1;
  48.  
  49. if (rolling == false)
  50. {
  51. Vector3 delta = anim.deltaPosition;
  52. delta.y = 0;
  53. Vector3 v = (delta * rm_multi) / states.delta;
  54. states.rigid.velocity = v;
  55. }
  56. else
  57. {
  58. roll_t += states.delta / 0.65f;
  59. if(roll_t > 1)
  60. {
  61. roll_t = 1;
  62. }
  63. float zValue = states.roll_curve.Evaluate(roll_t);
  64. Vector3 v1 = Vector3.forward * zValue;
  65. Vector3 relative = transform.TransformDirection(v1);
  66. Vector3 v2 = (relative * rm_multi);
  67. states.rigid.velocity = v2;
  68. }
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement