Game Development Community

dev|Pro Game Development Curriculum

Fix for FlyingVehicle maxForwardSpeed

by Hedd Roberts · 03/28/2010 (4:43 am) · 2 comments

Theres no way to set the speed limit on a flying vehicle, and with the fighter planes that are in my game, this wasnt realistic enough for my purposes!
MaxSpeed doesnt do it! Its used for something else.
Its a bit of a hack, but this adds a speed cap with minimal work.

In flyingVehicle.h inside: struct FlyingVehicleData: public VehicleData {

1) Find:

F32 createHoverHeight;

Add this after it:

F32 maxForwardSpeed;

2) Then in flyingVehicle.cc inside: FlyingVehicleData::FlyingVehicleData()

after this:

createHoverHeight = 2;

Add this:

maxForwardSpeed = 100;

3) Then inside: void FlyingVehicleData::initPersistFields()

After this:

addField("createHoverHeight", TypeF32, Offset(createHoverHeight, FlyingVehicleData));

Add this:

addField("maxForwardSpeed", TypeF32, Offset(maxForwardSpeed, FlyingVehicleData));

4) Then inside: void FlyingVehicleData::packData(BitStream* stream)

After this:

stream->write(createHoverHeight);

Add this:

stream->write(maxForwardSpeed);

5) Then inside: void FlyingVehicleData::unpackData(BitStream* stream)

After this:

stream->read(&createHoverHeight);

Add this:

stream->read(&maxForwardSpeed);

6) Then inside: void FlyingVehicle::updateForces(F32 /*dt*/)

BEFORE this:

// Maneuvering jets
force += yv * (mThrust.y * mDataBlock->maneuveringForce * mCeilingFactor);
force += xv * (mThrust.x * mDataBlock->maneuveringForce * mCeilingFactor);

Put this:

// Hedd - Speed cap
if (mRigid.linVelocity.len() > mDataBlock->maxForwardSpeed)
mCeilingFactor = 0;

Recompile!

7) Then just set your maxForwardSpeed in the flyingVehicle dataBlock

maxForwardSpeed = 150;

If you dont set a value the default is 100!

#1
03/28/2010 (6:23 am)
In addition to this: updateForces() may lead to a problem.
I believe it is called each frame, it means a slow hardware will call it less times compared to a fast hardware and this force will not increment equally on all cpus.
I think this is something you should test.

btw nice updates!
#2
03/28/2010 (7:00 am)
Thanks Ivan! I`ll check it out.