Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. // Created by Marco, major code rips off UT2004.
  2. Class ClientPawnAnimator extends Info;
  3.  
  4. var Pawn PawnOwner;
  5. var class<PawnAnimationGroup> AnimGroup;
  6.  
  7. var transient EPhysics OldPhysics,CurPhysics;
  8. var transient vector OldVelocity;
  9. var transient float IdleTime;
  10. var transient byte TurnDir,WeaponAnim,LookingDir,OldLookDir;
  11. var transient int SmoothViewYaw;
  12. var transient mesh OldMesh;
  13.  
  14. var transient bool bWaitForAnim,bIsIdle,bIsCrouched,bWasCrouched,FootTurning,bIsTyping,bIsWalking,bForceFinishAnim,bAnimWaitLanding,bAnimValid;
  15.  
  16. function Tick( float Delta )
  17. {
  18. if( PawnOwner==None || PawnOwner.bDeleteMe )
  19. {
  20. Destroy();
  21. return;
  22. }
  23. if( (Level.TimeSeconds - PawnOwner.LastRenderedTime)>1.0 || AnimGroup==None || PawnOwner.Health<=0 )
  24. {
  25. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  26. return;
  27. }
  28. if( OldMesh!=PawnOwner.Mesh )
  29. {
  30. OldMesh = PawnOwner.Mesh;
  31. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  32. bAnimValid = AnimGroup.Static.AnimatorValid(PawnOwner);
  33. }
  34. if( !bAnimValid )
  35. return;
  36. if( bForceFinishAnim )
  37. {
  38. if( PawnOwner.IsAnimating() )
  39. return;
  40. bForceFinishAnim = false;
  41. }
  42. CurPhysics = GetPawnPhysics();
  43. if( PawnOwner.Weapon==None || PawnOwner.Weapon.Mass<20 )
  44. WeaponAnim = 0;
  45. else WeaponAnim = 1;
  46.  
  47. if ( bIsIdle && CurPhysics!=OldPhysics )
  48. bWaitForAnim = false;
  49.  
  50. if( bAnimWaitLanding && CurPhysics!=PHYS_Falling )
  51. bAnimWaitLanding = false;
  52.  
  53. if ( !bWaitForAnim )
  54. {
  55. if ( CurPhysics==PHYS_Swimming )
  56. {
  57. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  58. UpdateSwimming();
  59. }
  60. else if ( CurPhysics==PHYS_Falling || CurPhysics==PHYS_Flying )
  61. {
  62. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  63. if( !bAnimWaitLanding )
  64. UpdateInAir();
  65. }
  66. else if ( CurPhysics==PHYS_Walking || CurPhysics==PHYS_Spider )
  67. UpdateOnGround();
  68. }
  69. else if ( !PawnOwner.IsAnimating() )
  70. bWaitForAnim = false;
  71.  
  72. if ( CurPhysics!=PHYS_Walking )
  73. bIsIdle = false;
  74.  
  75. OldPhysics = CurPhysics;
  76. OldVelocity = PawnOwner.Velocity;
  77. FootTurning = false;
  78. }
  79. final function PlayAnimation( name Anim, float Rate, optional float Tween, optional bool bLoop )
  80. {
  81. if( PawnOwner.AnimSequence==Anim )
  82. return;
  83. if( bLoop )
  84. PawnOwner.LoopAnim(Anim,Rate,Tween);
  85. else PawnOwner.PlayAnim(Anim,Rate,Tween);
  86. }
  87. final function TweenAnimation( name Anim, optional float Tween )
  88. {
  89. if( PawnOwner.AnimSequence==Anim && PawnOwner.AnimRate<=0 )
  90. return;
  91. PawnOwner.TweenAnim(Anim,Tween);
  92. }
  93.  
  94. final function UpdateSwimming()
  95. {
  96. if ( (PawnOwner.Velocity.X*PawnOwner.Velocity.X + PawnOwner.Velocity.Y*PawnOwner.Velocity.Y) < 2500.0f )
  97. PlayAnimation(AnimGroup.Default.IdleSwimAnim[WeaponAnim], 1.0f, 0.1f, true);
  98. else if( AnimGroup.Default.bDirectionalSwim )
  99. PlayAnimation(AnimGroup.Default.SwimAnims[Get4WayDirection(true)], 1.0f, 0.1f, true);
  100. else if( (vector(PawnOwner.Rotation) Dot Normal(PawnOwner.Velocity))>0.2f )
  101. PlayAnimation(AnimGroup.Default.SwimAnims[WeaponAnim], 1.0f, 0.1f, true);
  102. else PlayAnimation(AnimGroup.Default.IdleSwimAnim[WeaponAnim], 1.0f, 0.1f, true);
  103. }
  104. final function UpdateInAir()
  105. {
  106. local name NewAnim;
  107. local bool bUp, bDodge;
  108. local float DodgeSpeedThresh;
  109. local float XYVelocitySquared;
  110.  
  111. XYVelocitySquared = (PawnOwner.Velocity.X*PawnOwner.Velocity.X)+(PawnOwner.Velocity.Y*PawnOwner.Velocity.Y);
  112.  
  113. if ( OldPhysics == PHYS_Walking )
  114. {
  115. DodgeSpeedThresh = (PawnOwner.GroundSpeed*1.25f);
  116. if ( XYVelocitySquared > Square(DodgeSpeedThresh) )
  117. bDodge = true;
  118. }
  119.  
  120. bUp = (PawnOwner.Velocity.Z >= 0.0f);
  121.  
  122. if( XYVelocitySquared >= 20000.0f || AnimGroup.Default.TakeoffStillAnim=='' )
  123. {
  124. if (bDodge)
  125. {
  126. NewAnim = AnimGroup.Default.DodgeAnims[Get4WayDirection(AnimGroup.Default.bDirectionalDodge)];
  127. bAnimWaitLanding = true;
  128. }
  129. else if (bUp)
  130. NewAnim = AnimGroup.Default.TakeoffAnims[Get4WayDirection(AnimGroup.Default.bDirectionalAir)];
  131. else NewAnim = AnimGroup.Default.AirAnims[Get4WayDirection(AnimGroup.Default.bDirectionalAir)];
  132. }
  133. else if (bUp)
  134. NewAnim = AnimGroup.Default.TakeoffStillAnim;
  135. else NewAnim = AnimGroup.Default.AirStillAnim;
  136.  
  137. if ( NewAnim!=PawnOwner.AnimSequence )
  138. {
  139. if ( PawnOwner.Region.Zone.ZoneGravity.Z > (0.8f * PawnOwner.Region.Zone.Default.ZoneGravity.Z) )
  140. PawnOwner.PlayAnim(NewAnim, 0.5f, 0.2f); // Low grav slomo.
  141. else PawnOwner.PlayAnim(NewAnim, 1.25f, 0.1f);
  142. }
  143. }
  144. final function UpdateOnGround()
  145. {
  146. // just landed
  147. if ( OldPhysics == PHYS_Falling || OldPhysics == PHYS_Flying )
  148. PlayLand();
  149. // standing still
  150. else if ( (PawnOwner.Velocity.X*PawnOwner.Velocity.X)+(PawnOwner.Velocity.Y*PawnOwner.Velocity.Y)<2500.0f )
  151. {
  152. if( AnimGroup.Default.bDoIdleAiming )
  153. LookingDir = GetAimingDir(PawnOwner.Rotation.Pitch);
  154. UpdateTurning();
  155. if( !bIsIdle || FootTurning || bIsCrouched!=bWasCrouched || OldLookDir!=LookingDir || !PawnOwner.IsAnimating() )
  156. {
  157. IdleTime = Level.TimeSeconds;
  158. PlayIdle();
  159. }
  160. OldLookDir = LookingDir;
  161. bWasCrouched = bIsCrouched;
  162. bIsIdle = true;
  163. }
  164. // running
  165. else
  166. {
  167. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  168. if ( bIsIdle )
  169. bWaitForAnim = false;
  170.  
  171. PlayRunning();
  172. bIsIdle = false;
  173. }
  174. }
  175. final function byte GetAimingDir( int P )
  176. {
  177. if( bIsCrouched )
  178. return 0;
  179. P = P & 65535;
  180. if( P<2500 || P>63036 )
  181. return 0;
  182. if( P<32768 )
  183. return 2;
  184. return 1;
  185. }
  186. final function PlayIdle()
  187. {
  188. if (FootTurning)
  189. {
  190. if( AnimGroup.Default.bDirTurning )
  191. {
  192. if (bIsCrouched)
  193. PlayAnimation(AnimGroup.Default.CrouchTurnAnim[TurnDir], 1.0f, 0.1f);
  194. else PlayAnimation(AnimGroup.Default.TurnAnim[TurnDir], 1.0f, 0.1f);
  195. }
  196. else
  197. {
  198. if (bIsCrouched)
  199. PlayAnimation(AnimGroup.Default.CrouchTurnAnim[WeaponAnim], 1.0f, 0.1f);
  200. else PlayAnimation(AnimGroup.Default.TurnAnim[WeaponAnim], 1.0f, 0.1f);
  201. }
  202. }
  203. else
  204. {
  205. if (bIsCrouched)
  206. {
  207. if( AnimGroup.Default.IdleCrouchAnim[0]=='' )
  208. PlayAnimation(AnimGroup.Default.CrouchAnims[WeaponAnim], -2.f/PawnOwner.Default.GroundSpeed, 0.1f, true);
  209. else PlayAnimation(AnimGroup.Default.IdleCrouchAnim[WeaponAnim], 1.0f, 0.2f, true);
  210. }
  211. else
  212. {
  213. if ( bIsTyping )
  214. PlayAnimation(AnimGroup.Default.IdleChatAnim, 1.0f, 0.2f, true);
  215. else if( AnimGroup.Default.bDoIdleAiming && LookingDir>0 )
  216. PlayAnimation(AnimGroup.Default.IdleAiming[WeaponAnim*2+(LookingDir-1)], 1.0f, 0.25f);
  217. else if( FRand()<0.5 )
  218. PlayAnimation(AnimGroup.Default.IdleWeaponAnim[WeaponAnim], 1.0f, 0.25f, true);
  219. else PlayAnimation(AnimGroup.Default.IdleRestAnim[WeaponAnim], 1.0f, 0.25f, true);
  220. }
  221. }
  222. }
  223. final function PlayRunning()
  224. {
  225. local name NewAnim;
  226. local float AnimSpeed;
  227.  
  228. AnimSpeed = PawnOwner.Default.GroundSpeed;
  229. if (bIsCrouched)
  230. {
  231. NewAnim = AnimGroup.Default.CrouchAnims[Get4WayDirection(AnimGroup.Default.bDirCrouch)];
  232. AnimSpeed *= 0.5f;
  233. }
  234. else if (bIsWalking)
  235. {
  236. NewAnim = AnimGroup.Default.WalkAnims[Get4WayDirection(AnimGroup.Default.bDirWalk)];
  237. AnimSpeed *= 0.5f;
  238. }
  239. else NewAnim = AnimGroup.Default.MovementAnims[WeaponAnim+Get4WayDirection(AnimGroup.Default.bDirRun)*2];
  240.  
  241. if( PawnOwner.AnimSequence!=NewAnim )
  242. PawnOwner.LoopAnim(NewAnim, -1.f / AnimSpeed, 0.1f);
  243. }
  244. final function PlayLand()
  245. {
  246. if (!bIsCrouched)
  247. {
  248. PawnOwner.PlayAnim(AnimGroup.Default.LandAnims[Get4WayDirection(AnimGroup.Default.bDirLanding)], 1.0f, 0.1f);
  249. bWaitForAnim = true;
  250. }
  251. }
  252. final function UpdateTurning()
  253. {
  254. local int Y;
  255.  
  256. Y = (PawnOwner.Rotation.Yaw-SmoothViewYaw) & 65535;
  257. if( Y>32768 )
  258. Y-=65536;
  259. if( Y<4000 && Y>-4000 )
  260. return;
  261. SmoothViewYaw = PawnOwner.Rotation.Yaw;
  262. FootTurning = true;
  263. if( Y>0 )
  264. TurnDir = 1;
  265. else TurnDir = 0;
  266. }
  267.  
  268. final function EPhysics GetPawnPhysics()
  269. {
  270. local vector HL,HN,E,S;
  271.  
  272. if( PawnOwner.Role>=ROLE_AutonomousProxy )
  273. return PawnOwner.Physics;
  274. if( PawnOwner.Region.Zone.bWaterZone )
  275. return PHYS_Swimming;
  276. E.X = PawnOwner.CollisionRadius;
  277. E.Y = E.X;
  278. S = PawnOwner.Location;
  279. S.Z-=(PawnOwner.CollisionHeight-5);
  280. if( PawnOwner.Trace(HL,HN,S-vect(0,0,20),S,false,E)!=None && HN.Z>0.78 )
  281. return PHYS_Walking;
  282. return PHYS_Falling;
  283. }
  284. final function byte Get4WayDirection( bool bMultiDir )
  285. {
  286. local float DotVal;
  287. local vector V,X,Y,Z;
  288.  
  289. if( !bMultiDir )
  290. return WeaponAnim;
  291. V = PawnOwner.Velocity;
  292. V.Z = 0.0f;
  293.  
  294. if ( (V.X*V.X+V.Y*V.Y)<1.f )
  295. return 0;
  296.  
  297. GetAxes(PawnOwner.Rotation,X,Y,Z);
  298. V = Normal(V);
  299. DotVal = X dot V;
  300. if( DotVal>0.82f ) // 55 degrees
  301. return 0;
  302. if ( DotVal<-0.82f )
  303. return 1;
  304.  
  305. DotVal = Y dot V;
  306. if ( DotVal>0.0f )
  307. return 3;
  308. return 2;
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement