Code:
Auto State Flying
{
simulated function FaceRotation(rotator NewRotation, float DeltaTime)
//Simulated function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
Begin:
local vector X,Y,Z;
local float CurrentSpeed;
local float EngineAccel;
local float RotationSmoothFactor;
local float RollChange;
//local Rotator NewRotation;
SetPhysics(PHYS_Flying);
if ( !bPostNetCalled || Controller == None )
return;
if ( !bInitialized )
{
// Laurent -- Velocity Override
// When Player Spawns with the spaceship as Pawn, velocity is reset at start match
// since Rotation is overwritten later by Rotator(Velocity), it gets reset to Rotation(0,0,0)
// And therefore not using the one set in PlayerStart.Rotation
Acceleration = EngineMinVelocity * Vector(Rotation);
SpaceFighterRotation = QuatFromRotator( Rotation );
bInitialized = true;
}
// Only allow space fighter to change gear once landing gear is up.
// (small hack for fins animations)
if ( bGearUp == true )
DesiredVelocity = FClamp( DesiredVelocity+PlayerController(Controller).PlayerInput.aForward*DeltaTime/15.f,
EngineMinVelocity, 1000.f);
else
DesiredVelocity = EngineMinVelocity;
CurrentSpeed = FClamp( (Velocity Dot Vector(Rotation)) * 1000.f / AirSpeed, 1.f, 1000.f);
EngineAccel = (DesiredVelocity - CurrentSpeed) * 100.f;
RotationSmoothFactor = FClamp(1.f - RotationInertia * DeltaTime, 0.f, 1.f);
if ( PlayerController(Controller).PlayerInput.bDuck > 0 && Abs(Rotation.Roll) > 500 )
{
// Auto Correct Roll
if ( Rotation.Roll < 0 )
RollChange = RollAutoCorrectSpeed;
else
RollChange = -RollAutoCorrectSpeed;
}
else if ( PlayerController(Controller).PlayerInput.aUp > 0 ) // Rolling
RollChange = PlayerController(Controller).PlayerInput.aStrafe * 0.66;
// Rotation Acceleration
YawAccel = RotationSmoothFactor*YawAccel + DeltaTime*VehicleRotationSpeed*PlayerController(Controller).PlayerInput.aTurn*-1;
PitchAccel = RotationSmoothFactor*PitchAccel + DeltaTime*VehicleRotationSpeed*PlayerController(Controller).PlayerInput.aLookUp*-1;
RollAccel = RotationSmoothFactor*RollAccel + DeltaTime*VehicleRotationSpeed*RollChange;
YawAccel = FClamp( YawAccel, -1, 1 );
PitchAccel = FClamp( PitchAccel, -1, 1 );
RollAccel = FClamp( RollAccel, -1, 1 );
// Perform new rotation
GetAxes( QuatToRotator(SpaceFighterRotation), X, Y, Z );
SpaceFighterRotation = QuatProduct(SpaceFighterRotation,
QuatProduct(QuatFromAxisAndAngle(Y, DeltaTime*PitchAccel),
QuatProduct(QuatFromAxisAndAngle(Z, -1.0 * DeltaTime * YawAccel),
QuatFromAxisAndAngle(X, DeltaTime * RollAccel))));
NewRotation = QuatToRotator( SpaceFighterRotation );
// If autoadjusting roll, clamp to 0
if ( PlayerController(Controller).PlayerInput.bDuck > 0 && ((NewRotation.Roll < 0 && Rotation.Roll > 0) || (NewRotation.Roll > 0 && Rotation.Roll < 0)) )
{
NewRotation.Roll = 0;
RollAccel = 0;
}
Acceleration = Vector(NewRotation) * DesiredVelocity;
// strafing
StrafeAccel = RotationSmoothFactor*StrafeAccel;
if ( PlayerController(Controller).PlayerInput.aUp == 0 )
StrafeAccel += DeltaTime*StrafeAccelRate*PlayerController(Controller).PlayerInput.aStrafe;
StrafeAccel = FClamp( StrafeAccel, -MaxStrafe, MaxStrafe);
GetAxes( NewRotation, X, Y, Z );
Acceleration += StrafeAccel * Y;
// Adjust Rolling based on Stafing
NewRotation.Roll += StrafeAccel * 100;
DelayedDebugString = "NewRotation.Roll:" @ NewRotation.Roll @ "StrafeAccel:" @ StrafeAccel;
// Adjust Rolling based on Yaw
NewRotation.Roll += YawAccel * 100;
DelayedDebugString = "NewRotation.Roll:" @ NewRotation.Roll @ "StrafeAccel:" @ StrafeAccel;
// Take complete control on Rotation
bRotateToDesired = true;
bRollToDesired = true;
DesiredRotation = NewRotation;
SetRotation( NewRotation );
//WorldInfo.Game.Broadcast(self,"New Rotation is:" @NewRotation);
WorldInfo.Game.Broadcast(self,"***Velocity is" @Velocity);
WorldInfo.Game.Broadcast(self,"***AirSpeed is" @AirSpeed);
WorldInfo.Game.Broadcast(self,"***Accel is" @Acceleration);
WorldInfo.Game.Broadcast(self,"***CurrentSpeed is" @CurrentSpeed);
WorldInfo.Game.Broadcast(self,"This Thing That Is controlling it all is Rotation:" @Rotation);
}
event BeginState(Name PreviousStateName)
{
WorldInfo.Game.Broadcast(self,"***IT HAS BEGUN");
}
event EndState(Name NextStateName)
{
setPhysics(Phys_Falling);
WorldInfo.Game.Broadcast(PlayerController(Controller),"***IT HAS DIED.");
TakeDamage(Health*2, PlayerController(Controller), Location, vect(0,0,0), None);
}
goto 'Begin';
}
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
if ( Role == Role_Authority )
{
if ( !bPostNetCalled )
return;
//UpdateAutoTargetting();
// Hack when spacefighter gets stuck... kill!!
if ( VSize(Velocity) < 100 )
// TakeDamage(Health*2, Self, Location, vect(0,0,0), None);
WorldInfo.Game.Broadcast(PlayerController(Controller),"***I AM SUPPOSSED TO BE DEAD");
}
}
//event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
simulated function rotator GetViewRotation()
{
if ( IsLocallyControlled() && Health > 0 )
return QuatToRotator(SpaceFighterRotation); // true rotation
else
return Rotation;
}
}
Bookmarks