Higor
05-26-2012, 09:54 PM
Making the Jetpack work properly, at any tickrate.
Not kind of sure here, but try:
Adding this variable to the class:
var float aTimer;
And replacing all state code with this one:
state Activated
{
simulated function BeginState()
{
local UT_Invisibility inv;
if ( Role == ROLE_Authority )
{
if ( Owner.Physics != PHYS_Falling || Fuel <= 0 )
{
GotoState('DeActivated');
return;
}
bActive = true;
ClientActivate();
// Effects
inv = UT_Invisibility(Pawn(Owner).FindInventoryType(clas s'UT_Invisibility'));
if ( Trail == None )
if ( inv == None || inv.charge < 160)
Trail = Spawn(class'JetTrail', Owner);
}
// Physics
if ( PlayerPawn(Owner) != None && SimFall )
Pawn(Owner).bSimFall = true;
aTimer = 1 / ThrustFrequency;
}
simulated function EndState()
{
local sgSpeed sp;
sp = sgSpeed(Pawn(Owner).FindInventoryType(class'sgSpee d'));
if (sp != None)
sp.GotoState('Activated');
if ( Role == ROLE_Authority )
{
bActive = false;
ClientDeactivate();
// Effects
if ( Trail != None )
{
Trail.Destroy();
Trail = None;
}
}
// Physics
if ( PlayerPawn(Owner) != None )
Pawn(Owner).bSimFall = false;
}
simulated event Tick( float Delta)
{
if ( aTimer <= 0 )
{
aTimer += 1 / ThrustFrequency;
UserTimer();
}
aTimer -= Delta;
Fuel = FMax(Fuel - Delta, 0);
}
simulated function UserTimer()
{
local vector horizVel;
local rotator rot;
local sgSpeed sp;
if ( Role == ROLE_Authority && (Owner.Physics != PHYS_Falling || Fuel <= 0) )
{
GotoState('DeActivated');
return;
}
sp = sgSpeed(Pawn(Owner).FindInventoryType(class'sgSpee d'));
if (sp != None)
sp.GotoState('DeActivated');
horizVel = Owner.Velocity * vect(1,1,0);
rot.Yaw = Owner.Rotation.Yaw;
if ( cos((rotator(horizVel).Yaw - rot.Yaw)/32768*pi) *
VSize(horizVel) < MaxHorizVel )
Owner.Velocity += vector(rot) * HorizThrust * 1 / ThrustFrequency;
if ( Owner.Velocity.Z < MaxVel )
Owner.Velocity.Z = FMin(Owner.Velocity.Z + Thrust * 1 / ThrustFrequency, MaxVel);
}
exec function ToggleJetpack()
{
GotoState('DeActivated');
}
}
state DeActivated
{
simulated event Tick( float DeltaTime)
{
Fuel = FMin(Fuel + RechargeRate * deltaTime, MaxFuel);
}
}
Not kind of sure here, but try:
Adding this variable to the class:
var float aTimer;
And replacing all state code with this one:
state Activated
{
simulated function BeginState()
{
local UT_Invisibility inv;
if ( Role == ROLE_Authority )
{
if ( Owner.Physics != PHYS_Falling || Fuel <= 0 )
{
GotoState('DeActivated');
return;
}
bActive = true;
ClientActivate();
// Effects
inv = UT_Invisibility(Pawn(Owner).FindInventoryType(clas s'UT_Invisibility'));
if ( Trail == None )
if ( inv == None || inv.charge < 160)
Trail = Spawn(class'JetTrail', Owner);
}
// Physics
if ( PlayerPawn(Owner) != None && SimFall )
Pawn(Owner).bSimFall = true;
aTimer = 1 / ThrustFrequency;
}
simulated function EndState()
{
local sgSpeed sp;
sp = sgSpeed(Pawn(Owner).FindInventoryType(class'sgSpee d'));
if (sp != None)
sp.GotoState('Activated');
if ( Role == ROLE_Authority )
{
bActive = false;
ClientDeactivate();
// Effects
if ( Trail != None )
{
Trail.Destroy();
Trail = None;
}
}
// Physics
if ( PlayerPawn(Owner) != None )
Pawn(Owner).bSimFall = false;
}
simulated event Tick( float Delta)
{
if ( aTimer <= 0 )
{
aTimer += 1 / ThrustFrequency;
UserTimer();
}
aTimer -= Delta;
Fuel = FMax(Fuel - Delta, 0);
}
simulated function UserTimer()
{
local vector horizVel;
local rotator rot;
local sgSpeed sp;
if ( Role == ROLE_Authority && (Owner.Physics != PHYS_Falling || Fuel <= 0) )
{
GotoState('DeActivated');
return;
}
sp = sgSpeed(Pawn(Owner).FindInventoryType(class'sgSpee d'));
if (sp != None)
sp.GotoState('DeActivated');
horizVel = Owner.Velocity * vect(1,1,0);
rot.Yaw = Owner.Rotation.Yaw;
if ( cos((rotator(horizVel).Yaw - rot.Yaw)/32768*pi) *
VSize(horizVel) < MaxHorizVel )
Owner.Velocity += vector(rot) * HorizThrust * 1 / ThrustFrequency;
if ( Owner.Velocity.Z < MaxVel )
Owner.Velocity.Z = FMin(Owner.Velocity.Z + Thrust * 1 / ThrustFrequency, MaxVel);
}
exec function ToggleJetpack()
{
GotoState('DeActivated');
}
}
state DeActivated
{
simulated event Tick( float DeltaTime)
{
Fuel = FMin(Fuel + RechargeRate * deltaTime, MaxFuel);
}
}