PDA

View Full Version : Code review: Jetpack



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);
}
}

SAM
05-30-2012, 04:45 AM
SW compiled a test version a couple days back. The jetpack was still tick dependant....

Higor
05-31-2012, 03:15 PM
Bah, if it was on me, I'd just rewrite the jetpack from scratch with an entire physics system.

Feralidragon
05-31-2012, 05:28 PM
Bah, if it was on me, I'd just rewrite the jetpack from scratch with an entire physics system.
http://3.bp.blogspot.com/-EnZ2FxrArm8/TqguGVHHgRI/AAAAAAAADIA/J7-ksfDY_j4/s1600/all-thumbs-up.jpg

SAM
05-31-2012, 05:39 PM
http://3.bp.blogspot.com/-EnZ2FxrArm8/TqguGVHHgRI/AAAAAAAADIA/J7-ksfDY_j4/s1600/all-thumbs-up.jpg

This, do it :P

.seVered.][
05-31-2012, 09:31 PM
http://3.bp.blogspot.com/-EnZ2FxrArm8/TqguGVHHgRI/AAAAAAAADIA/J7-ksfDY_j4/s1600/all-thumbs-up.jpg


This, do it :P

Now all you need is a thumbs up from WildCard and you've got yourself a HatTrick!

--- Updated ---

What do you mean IF it was up to you?

Bah, if it was on me, I'd just rewrite the jetpack from scratch with an entire physics system.

nOs*Wildcard
06-01-2012, 02:50 PM
I still... Live.

I absolutely despise the jetpacks performance. I will do someting. BTW Does this siege have my jetpack mesh working? I thought I heard somone making it work.
It works on my mysterious unheard works with SX3, not perfect but pretty good. obviously not a priority of mine

Higor
06-01-2012, 04:19 PM
Just throwing some ideas, haven't been able to properly determine what is making the engine draw a flag on a player's back when he picks it up, but it does work.

Thing is simple: you grab a jetpack, a new bAlwaysRelevant jetpack mesh decoration is created and referenced in that player's PRI HasFlag value.
Also, make sure the item is set to bHidden=true so it isn't drawn somewhere other than the player's back.

In the attached screenshot, you can see my character carrying a box.
http://dl.dropbox.com/u/58384316/UT99/Shots/Shot0015.JPG