Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1.  
  2. float postSpeed;//the lower speed value that the character should use after the first time A_ChaseSmooth has been called,
  3. //to get out of tight spots from it's spawn position
  4. property PostSpeed : postSpeed;
  5. bool setPostSpeed;
  6. float turnSpeed;
  7. property TurnSpeed : turnSpeed;
  8. float angleTemp;
  9. float angleTarget;
  10. State chaseState;
  11. int chaseTic;//failsafe to ensure A_Chase is not called longer than the initial A_Chase frame length
  12.  
  13. Default
  14. {
  15. VoxelCharacter.TurnSpeed 15.0;
  16. }
  17.  
  18. override void Tick()
  19. {
  20. Super.Tick();
  21.  
  22. if (chaseState && CurState && tics != CurState.tics)
  23. {
  24. if (CurState == chaseState && chaseTic > 0)
  25. {
  26. chaseTic--;
  27. angleTemp = self.angle;
  28. A_Chase(null, null, CHF_NORANDOMTURN|CHF_NOPLAYACTIVE);
  29. //smooth turning
  30. double angDiff = DeltaAngle (angleTemp, self.angle);
  31. if (angDiff ~== 0)
  32. {
  33. return;
  34. }
  35. A_SetAngle(angleTemp + ((angDiff < 0) ? max (-turnSpeed, angDiff) : min (turnSpeed, angDiff)),SPF_INTERPOLATE);
  36. }
  37. else
  38. {
  39. chaseState = null;
  40. }
  41. }
  42. }
  43.  
  44. virtual void ChaseSmooth(int chaseLength = 1, StateLabel melee = '_a_chase_default', StateLabel missile = '_a_chase_default', int flags = 0)
  45. {
  46. //for the first time ChaseSmooth is called, call A_Chase as normal, but then set the speed to the lower value suitable for calling each tic.
  47. if(setPostSpeed == false)
  48. {
  49. setPostSpeed = true;
  50. A_Chase();
  51. speed = postSpeed;
  52. return;
  53. }
  54. chaseState = CurState;
  55. angleTemp = self.angle;
  56. chaseTic = chaseLength - 1;
  57. A_Chase(melee, missile, flags);
  58. //smooth turning
  59. double angDiff = DeltaAngle (angleTemp, self.angle);
  60. if (angDiff ~== 0)
  61. {
  62. return;
  63. }
  64. A_SetAngle(angleTemp + ((angDiff < 0) ? max (-turnSpeed, angDiff) : min (turnSpeed, angDiff)),SPF_INTERPOLATE);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement