Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Marco, major code rips off UT2004.
- Class ClientPawnAnimator extends Info;
- var Pawn PawnOwner;
- var class<PawnAnimationGroup> AnimGroup;
- var transient EPhysics OldPhysics,CurPhysics;
- var transient vector OldVelocity;
- var transient float IdleTime;
- var transient byte TurnDir,WeaponAnim,LookingDir,OldLookDir;
- var transient int SmoothViewYaw;
- var transient mesh OldMesh;
- var transient bool bWaitForAnim,bIsIdle,bIsCrouched,bWasCrouched,FootTurning,bIsTyping,bIsWalking,bForceFinishAnim,bAnimWaitLanding,bAnimValid;
- function Tick( float Delta )
- {
- if( PawnOwner==None || PawnOwner.bDeleteMe )
- {
- Destroy();
- return;
- }
- if( (Level.TimeSeconds - PawnOwner.LastRenderedTime)>1.0 || AnimGroup==None || PawnOwner.Health<=0 )
- {
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- return;
- }
- if( OldMesh!=PawnOwner.Mesh )
- {
- OldMesh = PawnOwner.Mesh;
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- bAnimValid = AnimGroup.Static.AnimatorValid(PawnOwner);
- }
- if( !bAnimValid )
- return;
- if( bForceFinishAnim )
- {
- if( PawnOwner.IsAnimating() )
- return;
- bForceFinishAnim = false;
- }
- CurPhysics = GetPawnPhysics();
- if( PawnOwner.Weapon==None || PawnOwner.Weapon.Mass<20 )
- WeaponAnim = 0;
- else WeaponAnim = 1;
- if ( bIsIdle && CurPhysics!=OldPhysics )
- bWaitForAnim = false;
- if( bAnimWaitLanding && CurPhysics!=PHYS_Falling )
- bAnimWaitLanding = false;
- if ( !bWaitForAnim )
- {
- if ( CurPhysics==PHYS_Swimming )
- {
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- UpdateSwimming();
- }
- else if ( CurPhysics==PHYS_Falling || CurPhysics==PHYS_Flying )
- {
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- if( !bAnimWaitLanding )
- UpdateInAir();
- }
- else if ( CurPhysics==PHYS_Walking || CurPhysics==PHYS_Spider )
- UpdateOnGround();
- }
- else if ( !PawnOwner.IsAnimating() )
- bWaitForAnim = false;
- if ( CurPhysics!=PHYS_Walking )
- bIsIdle = false;
- OldPhysics = CurPhysics;
- OldVelocity = PawnOwner.Velocity;
- FootTurning = false;
- }
- final function PlayAnimation( name Anim, float Rate, optional float Tween, optional bool bLoop )
- {
- if( PawnOwner.AnimSequence==Anim )
- return;
- if( bLoop )
- PawnOwner.LoopAnim(Anim,Rate,Tween);
- else PawnOwner.PlayAnim(Anim,Rate,Tween);
- }
- final function TweenAnimation( name Anim, optional float Tween )
- {
- if( PawnOwner.AnimSequence==Anim && PawnOwner.AnimRate<=0 )
- return;
- PawnOwner.TweenAnim(Anim,Tween);
- }
- final function UpdateSwimming()
- {
- if ( (PawnOwner.Velocity.X*PawnOwner.Velocity.X + PawnOwner.Velocity.Y*PawnOwner.Velocity.Y) < 2500.0f )
- PlayAnimation(AnimGroup.Default.IdleSwimAnim[WeaponAnim], 1.0f, 0.1f, true);
- else if( AnimGroup.Default.bDirectionalSwim )
- PlayAnimation(AnimGroup.Default.SwimAnims[Get4WayDirection(true)], 1.0f, 0.1f, true);
- else if( (vector(PawnOwner.Rotation) Dot Normal(PawnOwner.Velocity))>0.2f )
- PlayAnimation(AnimGroup.Default.SwimAnims[WeaponAnim], 1.0f, 0.1f, true);
- else PlayAnimation(AnimGroup.Default.IdleSwimAnim[WeaponAnim], 1.0f, 0.1f, true);
- }
- final function UpdateInAir()
- {
- local name NewAnim;
- local bool bUp, bDodge;
- local float DodgeSpeedThresh;
- local float XYVelocitySquared;
- XYVelocitySquared = (PawnOwner.Velocity.X*PawnOwner.Velocity.X)+(PawnOwner.Velocity.Y*PawnOwner.Velocity.Y);
- if ( OldPhysics == PHYS_Walking )
- {
- DodgeSpeedThresh = (PawnOwner.GroundSpeed*1.25f);
- if ( XYVelocitySquared > Square(DodgeSpeedThresh) )
- bDodge = true;
- }
- bUp = (PawnOwner.Velocity.Z >= 0.0f);
- if( XYVelocitySquared >= 20000.0f || AnimGroup.Default.TakeoffStillAnim=='' )
- {
- if (bDodge)
- {
- NewAnim = AnimGroup.Default.DodgeAnims[Get4WayDirection(AnimGroup.Default.bDirectionalDodge)];
- bAnimWaitLanding = true;
- }
- else if (bUp)
- NewAnim = AnimGroup.Default.TakeoffAnims[Get4WayDirection(AnimGroup.Default.bDirectionalAir)];
- else NewAnim = AnimGroup.Default.AirAnims[Get4WayDirection(AnimGroup.Default.bDirectionalAir)];
- }
- else if (bUp)
- NewAnim = AnimGroup.Default.TakeoffStillAnim;
- else NewAnim = AnimGroup.Default.AirStillAnim;
- if ( NewAnim!=PawnOwner.AnimSequence )
- {
- if ( PawnOwner.Region.Zone.ZoneGravity.Z > (0.8f * PawnOwner.Region.Zone.Default.ZoneGravity.Z) )
- PawnOwner.PlayAnim(NewAnim, 0.5f, 0.2f); // Low grav slomo.
- else PawnOwner.PlayAnim(NewAnim, 1.25f, 0.1f);
- }
- }
- final function UpdateOnGround()
- {
- // just landed
- if ( OldPhysics == PHYS_Falling || OldPhysics == PHYS_Flying )
- PlayLand();
- // standing still
- else if ( (PawnOwner.Velocity.X*PawnOwner.Velocity.X)+(PawnOwner.Velocity.Y*PawnOwner.Velocity.Y)<2500.0f )
- {
- if( AnimGroup.Default.bDoIdleAiming )
- LookingDir = GetAimingDir(PawnOwner.Rotation.Pitch);
- UpdateTurning();
- if( !bIsIdle || FootTurning || bIsCrouched!=bWasCrouched || OldLookDir!=LookingDir || !PawnOwner.IsAnimating() )
- {
- IdleTime = Level.TimeSeconds;
- PlayIdle();
- }
- OldLookDir = LookingDir;
- bWasCrouched = bIsCrouched;
- bIsIdle = true;
- }
- // running
- else
- {
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- if ( bIsIdle )
- bWaitForAnim = false;
- PlayRunning();
- bIsIdle = false;
- }
- }
- final function byte GetAimingDir( int P )
- {
- if( bIsCrouched )
- return 0;
- P = P & 65535;
- if( P<2500 || P>63036 )
- return 0;
- if( P<32768 )
- return 2;
- return 1;
- }
- final function PlayIdle()
- {
- if (FootTurning)
- {
- if( AnimGroup.Default.bDirTurning )
- {
- if (bIsCrouched)
- PlayAnimation(AnimGroup.Default.CrouchTurnAnim[TurnDir], 1.0f, 0.1f);
- else PlayAnimation(AnimGroup.Default.TurnAnim[TurnDir], 1.0f, 0.1f);
- }
- else
- {
- if (bIsCrouched)
- PlayAnimation(AnimGroup.Default.CrouchTurnAnim[WeaponAnim], 1.0f, 0.1f);
- else PlayAnimation(AnimGroup.Default.TurnAnim[WeaponAnim], 1.0f, 0.1f);
- }
- }
- else
- {
- if (bIsCrouched)
- {
- if( AnimGroup.Default.IdleCrouchAnim[0]=='' )
- PlayAnimation(AnimGroup.Default.CrouchAnims[WeaponAnim], -2.f/PawnOwner.Default.GroundSpeed, 0.1f, true);
- else PlayAnimation(AnimGroup.Default.IdleCrouchAnim[WeaponAnim], 1.0f, 0.2f, true);
- }
- else
- {
- if ( bIsTyping )
- PlayAnimation(AnimGroup.Default.IdleChatAnim, 1.0f, 0.2f, true);
- else if( AnimGroup.Default.bDoIdleAiming && LookingDir>0 )
- PlayAnimation(AnimGroup.Default.IdleAiming[WeaponAnim*2+(LookingDir-1)], 1.0f, 0.25f);
- else if( FRand()<0.5 )
- PlayAnimation(AnimGroup.Default.IdleWeaponAnim[WeaponAnim], 1.0f, 0.25f, true);
- else PlayAnimation(AnimGroup.Default.IdleRestAnim[WeaponAnim], 1.0f, 0.25f, true);
- }
- }
- }
- final function PlayRunning()
- {
- local name NewAnim;
- local float AnimSpeed;
- AnimSpeed = PawnOwner.Default.GroundSpeed;
- if (bIsCrouched)
- {
- NewAnim = AnimGroup.Default.CrouchAnims[Get4WayDirection(AnimGroup.Default.bDirCrouch)];
- AnimSpeed *= 0.5f;
- }
- else if (bIsWalking)
- {
- NewAnim = AnimGroup.Default.WalkAnims[Get4WayDirection(AnimGroup.Default.bDirWalk)];
- AnimSpeed *= 0.5f;
- }
- else NewAnim = AnimGroup.Default.MovementAnims[WeaponAnim+Get4WayDirection(AnimGroup.Default.bDirRun)*2];
- if( PawnOwner.AnimSequence!=NewAnim )
- PawnOwner.LoopAnim(NewAnim, -1.f / AnimSpeed, 0.1f);
- }
- final function PlayLand()
- {
- if (!bIsCrouched)
- {
- PawnOwner.PlayAnim(AnimGroup.Default.LandAnims[Get4WayDirection(AnimGroup.Default.bDirLanding)], 1.0f, 0.1f);
- bWaitForAnim = true;
- }
- }
- final function UpdateTurning()
- {
- local int Y;
- Y = (PawnOwner.Rotation.Yaw-SmoothViewYaw) & 65535;
- if( Y>32768 )
- Y-=65536;
- if( Y<4000 && Y>-4000 )
- return;
- SmoothViewYaw = PawnOwner.Rotation.Yaw;
- FootTurning = true;
- if( Y>0 )
- TurnDir = 1;
- else TurnDir = 0;
- }
- final function EPhysics GetPawnPhysics()
- {
- local vector HL,HN,E,S;
- if( PawnOwner.Role>=ROLE_AutonomousProxy )
- return PawnOwner.Physics;
- if( PawnOwner.Region.Zone.bWaterZone )
- return PHYS_Swimming;
- E.X = PawnOwner.CollisionRadius;
- E.Y = E.X;
- S = PawnOwner.Location;
- S.Z-=(PawnOwner.CollisionHeight-5);
- if( PawnOwner.Trace(HL,HN,S-vect(0,0,20),S,false,E)!=None && HN.Z>0.78 )
- return PHYS_Walking;
- return PHYS_Falling;
- }
- final function byte Get4WayDirection( bool bMultiDir )
- {
- local float DotVal;
- local vector V,X,Y,Z;
- if( !bMultiDir )
- return WeaponAnim;
- V = PawnOwner.Velocity;
- V.Z = 0.0f;
- if ( (V.X*V.X+V.Y*V.Y)<1.f )
- return 0;
- GetAxes(PawnOwner.Rotation,X,Y,Z);
- V = Normal(V);
- DotVal = X dot V;
- if( DotVal>0.82f ) // 55 degrees
- return 0;
- if ( DotVal<-0.82f )
- return 1;
- DotVal = Y dot V;
- if ( DotVal>0.0f )
- return 3;
- return 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement