UMSPawn
Class MoviePawn

source: e:\games\UnrealTournament\UMSPawn\Classes\MoviePawn.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Pawn
         |
         +--UMSPawn.MoviePawn
Direct Known Subclasses:AccelerateMoviePawn, AttatchMoviePawn

class MoviePawn
extends Engine.Pawn

//============================================================================= // MoviePawn. //=============================================================================
Variables
 Actor CircleTarget
 vector CirclingOffset
 rotator CirclingSpeed
 vector DesiredLocation
 rotator FiringRotation
 float Foot1Time
 float Foot2Time
 int FootStepAnimNum
 float FootStepLoopTime
 float FootStepTime
 float MoveAcceleration
 vector MoveChange
 Actor MoveTarget
 float MoveTime
 vector OriginalMoveLocation
 vector Radius
 rotator RotChange
 Actor RotTarget
 float RotTime
 rotator TargetRotation
 float TotalMoveTime
 rotator TrackingDirections
 vector TrackingOffset
 Actor TrackingTarget
 bool bAccelerating
 bool bCircling
 bool bFlip
 bool bFlipNext
 bool bFootSteps
 bool bInterpolating
 bool bLoopingSteps
 bool bMoving
 bool bPlayedFoot1
 bool bPlayedFoot2
 bool bRotating
 bool bTracking

States
FinishAnimating

Function Summary
 rotator AdjustAim(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
 float CalcAccelPos(float Time, float TotalTime, float Acceleration)
 float DetermineRate(float Time)
 void DoAccelMove(vector TargetLocation, float Time, float Acceleration)
 void DoAltFire(vector TargetLocation, vector Offset)
 void DoChangeMesh(mesh NewMesh)
     
/* 
 void DoCircling(Actor NewTarget, rotator Speed, vector Offset, float Distance)
 void DoFire(vector TargetLocation, vector Offset)
 void DoHardStop()
 void DoInterpolate(Actor InterpPoint, float DesiredRate, float DesiredAlpha)
 void DoLoopAnim(name AnimSeq, float Time, float TweenTime)
 void DoMove(vector TargetLocation, Actor NewTarget, float Time)
 void DoPlayAnim(name AnimSeq, float Time, float TweenTime)
 void DoRotate(rotator NewRotation, Actor NewTarget, float Time)
 void DoSoftStop()
 void DoTracking(Actor NewTarget, vector Offset, rotator Directions)
 void InterpolateEnd(Actor InterpPoint)
     
//This is in there to handle the end of an interpolation
 void TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
 void TakeFallingDamage()
     
//Stuff we want to override from the Pawn superclass so that they
//do nothing.


State FinishAnimating Function Summary



Source Code


00001	//=============================================================================
00002	// MoviePawn.
00003	//=============================================================================
00004	class MoviePawn expands Pawn;
00005	
00006	//The number of units of rotation that make up half a full rotation,
00007	//or one Pi radians.
00008	const RotPiVal = 32768;
00009	//If the pawn is rotating.
00010	var bool bRotating;
00011	//The rotation to go to
00012	var rotator TargetRotation;
00013	//The number of seconds to spend rotating
00014	var float RotTime;
00015	//The change in rotation per second
00016	var rotator RotChange;
00017	//The actor the pawn is trying to rotate towards
00018	var actor RotTarget;
00019	//If the pawn is moving.
00020	var bool bMoving;
00021	var bool bInterpolating;
00022	//The location the pawn is trying to move to.
00023	var vector DesiredLocation;
00024	var float MoveAcceleration;
00025	var bool bAccelerating;
00026	//The number of seconds to spend moving.
00027	var float MoveTime;
00028	var float TotalMoveTime;
00029	//The change in location per second.
00030	var vector MoveChange;
00031	var vector OriginalMoveLocation;
00032	//The actor the pawn is trying to move to
00033	var actor MoveTarget;
00034	//The pawn must stay facing the TrackingTarget.
00035	var bool bTracking;
00036	//The offset while tracking
00037	var vector TrackingOffset;
00038	//The actor the pawn is tracking
00039	var Actor TrackingTarget;
00040	//The directions that will be tracked.  If the value is greater than
00041	//or equal to zero that kind of rotation will be used to track.  So
00042	//only if you don't want to track in a given direction will you want
00043	//to set one of the values to -1.
00044	var rotator TrackingDirections;
00045	//The pawn is circling some point, or some moving actor, but not
00046	//facing it (unless combined with tracking).
00047	var bool bCircling;
00048	//The radius between the point and the pawn that the camera uses
00049	//to rotate.
00050	var vector Radius;
00051	//The change of rotation per second while circling
00052	var rotator CirclingSpeed;
00053	//The offset while circing
00054	var vector CirclingOffset;
00055	//The actor the pawn is circling.
00056	var actor CircleTarget;
00057	//The pawn needs to flip due to circling over a tracked target.
00058	var bool bFlip;
00059	var bool bFlipNext;
00060	//The rotation the Pawn wants to fire at
00061	var rotator FiringRotation;
00062	// The different footstep sounds that can be played when the pawn walks or runs
00063	var(FootSteps) sound FootSteps[6];
00064	// Up to six different animations can have footsteps
00065	var(FootSteps) name FootStepAnimation[6];
00066	// The two frames where a foot hits the ground
00067	var(FootSteps) int Foot1Frame[6];
00068	var(FootSteps) int Foot2Frame[6];
00069	// The volume of the footsteps (can be different for each animation)
00070	var(FootSteps) byte FootStepVolume[6];
00071	// The total number of frames in that animation
00072	var(FootSteps) int TotalFrames[6];
00073	// The number of the animation that is being played
00074	var int FootStepAnimNum;
00075	// Whether there are footsteps or not
00076	var bool bFootSteps;
00077	// Whether the footsteps are looping
00078	var bool bLoopingSteps;
00079	// The time of one loop of the animation
00080	var float FootStepTime;
00081	// The time before the first and second footsteps
00082	var float Foot1Time;
00083	var float Foot2Time;
00084	// The time since that loop started
00085	var float FootStepLoopTime;
00086	// Whether the two footsteps have been played yet
00087	var bool bPlayedFoot1;
00088	var bool bPlayedFoot2;
00089	
00090	
00091	//Just like with the camera, tick is where most things happen.  The
00092	//position, rotation, ect. of the pawn is updated here.
00093	//
00094	//Just like the camera, these do functions are called by the director
00095	//to set up and start various actions.
00096	//
00097	//Invalid Combinations:
00098	//	+ Circling with moving.
00099	//	+ Tracking with rotating.
00100	//  + Rotating with tracking.
00101	//  + Moving with circling.
00102	//
00103	event Tick(float DeltaTime)
00104	{
00105	    local vector TempVec, X, Y, Z;
00106	    local rotator TempRot, TempRot2;
00107	    local int RandFootStep;
00108	
00109	    log(self$": Tick() called in MoviePawn");
00110	    
00111	    // Check for footsteps
00112	    if(bFootSteps)
00113	    {
00114	        if(bLoopingSteps)
00115	        {
00116	            FootStepLoopTime += DeltaTime;
00117	            if(!bPlayedFoot1 && FootStepLoopTime >= Foot1Time)
00118	            {
00119	                RandFootStep = Rand(6);
00120	                PlaySound(FootSteps[RandFootStep],,FootStepVolume[FootStepAnimNum]);
00121	            }
00122	            if(!bPlayedFoot2 && FootStepLoopTime >= Foot2Time)
00123	            {
00124	                RandFootStep = Rand(6);
00125	                PlaySound(FootSteps[RandFootStep],,FootStepVolume[FootStepAnimNum]);
00126	            }
00127	            if(FootStepLoopTime >= FootStepTime)
00128	            {
00129	                FootStepLoopTime = 0;
00130	            }
00131	        }
00132	        else
00133	        {
00134	            FootStepLoopTime += DeltaTime;
00135	            if(!bPlayedFoot1 && FootStepLoopTime >= Foot1Time)
00136	            {
00137	                RandFootStep = Rand(6);
00138	                PlaySound(FootSteps[RandFootStep],,FootStepVolume[FootStepAnimNum]);
00139	            }
00140	            if(!bPlayedFoot2 && FootStepLoopTime >= Foot2Time)
00141	            {
00142	                RandFootStep = Rand(6);
00143	                PlaySound(FootSteps[RandFootStep],,FootStepVolume[FootStepAnimNum]);
00144	            }
00145	            if(FootStepLoopTime >= FootStepTime)
00146	            {
00147	                bFootSteps = false;
00148	            }
00149	        }
00150	    }
00151	
00152		//Check for interpolation
00153		if(bInterpolating)
00154		{
00155			log(self$": Interpolating");
00156			//Do nothing, regular physics will handle this
00157		}
00158		else
00159			SetPhysics(PHYS_None);
00160	
00161	    //Check for rotating
00162		if(bRotating)
00163		{
00164			//First, do update for moving target/pawn if neccesary.
00165			if(RotTarget != NONE)
00166			{
00167				TempRot = rotator(RotTarget.Location - Location);
00168				DoRotate(TempRot, RotTarget, RotTime);
00169			}
00170			
00171			//We need a check to see if it is done.
00172			if(RotTime <= DeltaTime)
00173			{
00174				SetRotation(TargetRotation);
00175				bRotating = false;
00176			}
00177			else
00178			{
00179				SetRotation(Rotation + (RotChange * DeltaTime));
00180				RotTime -= DeltaTime;
00181			}
00182		}
00183		
00184		if(bAccelerating)
00185		{
00186			if(MoveTime <= DeltaTime)
00187			{
00188				SetLocation(DesiredLocation);
00189				bAccelerating = false;
00190			}
00191			else
00192			{
00193				TempVec = (CalcAccelPos(MoveTime, TotalMoveTime, MoveAcceleration) * MoveChange);
00194				SetLocation(OriginalMoveLocation + TempVec);
00195				MoveTime -= DeltaTime;
00196			}
00197		}
00198		
00199		//Check for moving
00200		if(bMoving)
00201		{
00202			//First, do update for moving target if neccesary.
00203			if(MoveTarget != NONE)
00204			{
00205				TempVec = MoveTarget.Location;
00206				DoMove(TempVec, MoveTarget, MoveTime);
00207			}
00208	
00209			//Check to make sure you do not over-move
00210			if(MoveTime <= DeltaTime)
00211			{
00212				//SetLocation(DesiredLocation);
00213				bMoving = false;
00214			}
00215			else
00216			{
00217				SetLocation(Location + (MoveChange * DeltaTime));
00218				MoveTime -= DeltaTime;
00219			}
00220		}
00221		
00222		//Check for circling
00223		if(bCircling)
00224		{	
00225			//First, check to see if we have lost our target.
00226			if(CircleTarget == NONE)
00227				bCircling = false;
00228			else
00229			{
00230				TempRot = rotator(Radius);
00231				TempRot2 = CirclingSpeed * DeltaTime;
00232				
00233				//Check for over-head switch
00234				if(abs(TempRot.Pitch + TempRot2.Pitch) > (RotPiVal/2))
00235				{
00236					TempRot.Yaw += RotPiVal;
00237					CirclingSpeed.Pitch *= -1;
00238					//Flip the camera over so it does not look goofy.
00239					bFlip = !bFlip;
00240				}
00241				
00242				TempRot += CirclingSpeed * DeltaTime;			
00243				TempVec = vector(TempRot) * VSize(Radius);
00244				Radius = TempVec;
00245				SetLocation(CircleTarget.Location + Radius + CirclingOffset);
00246			}
00247		}
00248		
00249		//Check for tracking
00250		if(bTracking)
00251		{
00252			//First, check to see if we have lost our target.
00253			if(TrackingTarget == NONE)
00254				bTracking = false;
00255			else
00256			{
00257				TempVec = (TrackingTarget.Location + TrackingOffset) - Location;
00258				TempRot = rotator(TempVec);
00259				//Examine TrackingDirections to determine how to track.
00260				if(TrackingDirections.Yaw < 0)
00261					TempRot.Yaw = 0;
00262				if(TrackingDirections.Pitch < 0)
00263					TempRot.Pitch = 0;
00264				if(TrackingDirections.Roll < 0)
00265					TempRot.Roll = 0;
00266				//Flip over the camera if needed.
00267				if(bFlip)
00268				{
00269					TempRot.Roll += RotPiVal;
00270				}
00271				SetRotation(TempRot);
00272				
00273			}
00274		}
00275	}
00276	
00277	function float CalcAccelPos(float Time, float TotalTime, float Acceleration)
00278	{
00279		local float CurrentPoint;
00280		local float CurrentPoint2;
00281		local float TempFloat, TempFloat2;
00282		
00283		CurrentPoint = (TotalTime - Time) / TotalTime;
00284		if(Acceleration < 2)
00285			return CurrentPoint;
00286		
00287		TempFloat = Acceleration - 5;
00288		TempFloat2 = ((TempFloat + Sqrt(Square(TempFloat) + 4)) / 2) - 0.2;
00289		
00290		TempFloat = (Acceleration * CurrentPoint) - 5;
00291		CurrentPoint2 = (((TempFloat + Sqrt(Square(TempFloat) + 4)) / 2) - 0.2) / TempFloat2;
00292	
00293		return CurrentPoint2;
00294	}
00295	
00296	function DoInterpolate(actor InterpPoint, float DesiredRate, float DesiredAlpha)
00297	{
00298		log(self$": About to start interpolating");
00299		
00300		//Check for no target
00301		if(InterpPoint == NONE)
00302			bInterpolating = false;
00303		else
00304		{
00305			log(self$": Starting to interpolate");
00306			SetCollision(True,false,false);
00307			bCollideWorld = False ;
00308			Target = InterpPoint;
00309			SetPhysics(PHYS_Interpolating);
00310			PhysRate = DesiredRate;
00311			PhysAlpha = DesiredAlpha;
00312			bInterpolating = true;
00313			bMoving = false;
00314			bAccelerating = false;
00315			bCircling = false;
00316		}
00317	}
00318	
00319	function DoAccelMove(vector TargetLocation, float Time, float Acceleration)
00320	{
00321		//Check for instant move.
00322		if(Time == 0)
00323		{
00324			SetLocation(TargetLocation);
00325			bAccelerating = false;
00326		}		
00327		else
00328		{
00329			DesiredLocation = TargetLocation;
00330			OriginalMoveLocation = Location;
00331			bMoving = false;
00332			bAccelerating = true;
00333			bInterpolating = false;
00334			bCircling = false;
00335			MoveTime = Time;
00336			TotalMoveTime = Time;
00337			MoveAcceleration = Acceleration;
00338			MoveChange = (DesiredLocation - Location);
00339		}
00340	}
00341	
00342	function DoPlayAnim(name AnimSeq, float Time, float TweenTime)
00343	{
00344	    local float Rate;
00345	    local int i;
00346	
00347	    for(i=0;i<6;i++)
00348	    {
00349	        if(AnimSeq == FootStepAnimation[i])
00350	        {
00351	            bFootSteps = true;
00352	            bLoopingSteps = false;
00353	            bPlayedFoot1 = false;
00354	            bPlayedFoot2 = false;
00355	            FootStepAnimNum = i;
00356	            FootStepTime = Time;
00357	            Foot1Time = (Foot1Frame[i] / TotalFrames[i]) * FootStepTime;
00358	            Foot2Time = (Foot2Frame[i] / TotalFrames[i]) * FootStepTime;
00359	            FootStepLoopTime = 0;
00360	            break;
00361	        }
00362	    }
00363	
00364	    PlayAnim(AnimSeq, 1, 0);
00365	    Rate = DetermineRate(Time);
00366	    PlayAnim(AnimSeq, Rate, TweenTime);
00367	}
00368	
00369	function DoLoopAnim(name AnimSeq, float Time, float TweenTime)
00370	{
00371	    local float Rate;
00372	    local int i;
00373		
00374	    for(i=0;i<6;i++)
00375	    {
00376	        if(AnimSeq == FootStepAnimation[i])
00377	        {
00378	            bFootSteps = true;
00379	            bLoopingSteps = true;
00380	            bPlayedFoot1 = false;
00381	            bPlayedFoot2 = false;
00382	            FootStepAnimNum = i;
00383	            FootStepTime = Time;
00384	            Foot1Time = (Foot1Frame[i] / TotalFrames[i]) * FootStepTime;
00385	            Foot2Time = (Foot2Frame[i] / TotalFrames[i]) * FootStepTime;
00386	            FootStepLoopTime = 0;
00387	            break;
00388	        }
00389	    }
00390	
00391	    LoopAnim(AnimSeq, 1, 0);
00392	    Rate = DetermineRate(Time);
00393	    LoopAnim(AnimSeq, Rate, TweenTime);
00394	}
00395	
00396	function float DetermineRate(float Time)
00397	{
00398		local float FramesLeft, CurSecsLeft, Ratio;
00399		FramesLeft = 1 - AnimFrame;
00400		CurSecsLeft = FramesLeft / AnimRate;
00401		Ratio = CurSecsLeft / Time;
00402		return Ratio;
00403	} 
00404	
00405	function DoSoftStop()
00406	{
00407		GotoState('FinishAnimating');
00408	}
00409	
00410	function DoHardStop()
00411	{
00412		PlayAnim(AnimSequence, 100000, 0);
00413	}
00414	
00415	function DoMove(vector TargetLocation, actor NewTarget, float Time)
00416	{
00417		//Check for instant move.
00418		if(Time == 0)
00419		{
00420			SetLocation(TargetLocation);
00421			bMoving = false;
00422		}		
00423		else
00424		{
00425			DesiredLocation = TargetLocation;
00426			MoveTarget = NewTarget;
00427			bMoving = true;
00428			bAccelerating = false;
00429			bInterpolating = false;
00430			bCircling = false;
00431			MoveTime = Time;
00432			MoveChange = (DesiredLocation - Location) / MoveTime;
00433		}
00434	}
00435	
00436	function DoRotate(rotator NewRotation, actor NewTarget, float Time)
00437	{
00438		//Check for instant rotate.
00439		if(Time == 0)
00440		{
00441			SetRotation(NewRotation);
00442			bRotating = false;
00443		}		
00444		else
00445		{
00446			bRotating = true;
00447			bTracking = false;
00448			RotTime = Time;
00449			RotTarget = NewTarget;
00450			TargetRotation = NewRotation;
00451	        while((TargetRotation.yaw - Rotation.yaw) > 32768)
00452	        {
00453	            TargetRotation.yaw -= 65536;
00454	        }
00455	        while((TargetRotation.pitch - Rotation.pitch) > 32768)
00456	        {                  
00457	            TargetRotation.pitch -= 65536;
00458	        }
00459	        while((TargetRotation.roll - Rotation.roll) > 32768)
00460	        {
00461	            TargetRotation.roll -= 65536;
00462	        }
00463	        while((TargetRotation.yaw - Rotation.yaw) < -32768)
00464	        {
00465	            TargetRotation.yaw += 65536;
00466	        }
00467	        while((TargetRotation.pitch - Rotation.pitch) < -32768)
00468	        {                  
00469	            TargetRotation.pitch += 65536;
00470	        }
00471	        while((TargetRotation.roll - Rotation.roll) < -32768)
00472	        {
00473	            TargetRotation.roll += 65536;
00474	        }
00475			RotChange = (TargetRotation - Rotation) / RotTime;
00476		}
00477	}
00478	
00479	function DoFire(vector TargetLocation, vector Offset)
00480	{
00481		local vector Start, X, Y, Z;
00482		
00483		GetAxes(ViewRotation, X, Y, Z);
00484		Weapon.FireOffset = Offset;
00485		Start = Location + Weapon.CalcDrawOffset() + Weapon.FireOffset.X
00486		* X + Weapon.FireOffset.Y * Y + Weapon.FireOffset.Z * Z;
00487		FiringRotation = rotator(TargetLocation - Start);
00488		Weapon.Fire(0);
00489	}
00490	
00491	
00492	function DoAltFire(vector TargetLocation, vector Offset)
00493	{
00494		local vector Start, X, Y, Z;
00495		
00496		GetAxes(ViewRotation, X, Y, Z);
00497		Weapon.FireOffset = Offset;
00498		Start = Location + Weapon.CalcDrawOffset() + Weapon.FireOffset.X
00499		* X + Weapon.FireOffset.Y * Y + Weapon.FireOffset.Z * Z;
00500		FiringRotation = rotator(TargetLocation - Start);
00501		Weapon.AltFire(0);
00502	}
00503	
00504	function DoCircling(actor NewTarget, rotator Speed, vector Offset, float Distance)
00505	{
00506		//Check for no target.
00507		if(NewTarget == NONE)
00508			bCircling = false;
00509		else
00510		{
00511			bCircling = true;
00512			bMoving = false;
00513			bInterpolating = false;
00514			bAccelerating = false;
00515			CircleTarget = NewTarget;
00516			Radius = -1 * (CircleTarget.Location - Location);
00517			if(Distance != 0)
00518				Radius = (Radius / VSize(Radius)) * Distance;
00519			CirclingSpeed = Speed;
00520			CirclingOffset = Offset;
00521		}
00522	}
00523	
00524	function DoTracking(actor NewTarget, vector Offset, rotator Directions)
00525	{
00526		//Check for no target.
00527		if(NewTarget == NONE)
00528			bTracking = false;
00529		else
00530		{
00531			bTracking = true;
00532			bRotating = false;
00533			TrackingTarget = NewTarget;
00534			TrackingOffset = Offset;
00535			TrackingDirections = Directions;
00536		}
00537	}
00538	
00539	//This is in there to handle the end of an interpolation
00540	function InterpolateEnd(actor InterpPoint)
00541	{
00542		if(InterpolationPoint(InterpPoint).bEndOfPath)
00543		{
00544			SetPhysics(PHYS_None);
00545			bInterpolating = false;
00546		}
00547	}
00548	
00549	function rotator AdjustAim(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
00550	{
00551		return FiringRotation;
00552	}
00553	
00554	//Stuff we want to override from the Pawn superclass so that they
00555	//do nothing.
00556	function TakeFallingDamage()
00557	{				
00558	}
00559	
00560	function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
00561	{
00562	}
00563	
00564	
00565	/* function DoChangeMesh(mesh NewMesh)
00566	{ 
00567		Mesh = NewMesh;
00568	} */
00569	
00570	
00571	//This state is used to stop an animation that is already in progress.
00572	//It is here because FinishAnim has to be called from a state, since
00573	//it is a latent function.
00574	state FinishAnimating
00575	{
00576		begin:
00577			FinishAnim();
00578	}
00579	
00580	defaultproperties
00581	{
00582	     BaseEyeHeight=23.000000
00583	     Intelligence=BRAINS_NONE
00584	     DrawType=DT_Mesh
00585	     Mesh=LodMesh'UnrealShare.Nali1'
00586	}

End Source Code