Game Development Community

Flying vehicle Fix

by Brian Kirchgessner · 03/17/2006 (7:01 pm) · 15 comments

Ok, this is a small fix for the Flying vehicles code to stop it from crashing for speeds above 40,000.

In Flyingvehicle.cc replace:
force -= xv * speed * mDot(xv,mRigid.state.linVelocity) * mDataBlock->horizontalSurfaceForce;
force -= zv * speed * mDot(zv,mRigid.state.linVelocity) * mDataBlock->verticalSurfaceForce;
with this:
force -= xv * mDot(xv,mRigid.state.linVelocity) * mDataBlock->horizontalSurfaceForce;
force -= zv * mDot(zv,mRigid.state.linVelocity) * mDataBlock->verticalSurfaceForce;

that fix was done by [b]Sebasti

#1
03/02/2006 (12:39 am)
Ok to seperate the steering forces,

to save space I'm cutting down some of the code hence the long "........." you'll see every where.

start off with the Flyingvehicle.h
struct FlyingVehicleData: public VehicleData........
      
   F32 autoInputDamping;  [b]
   F32 steeringForceY;  
   F32 steeringForceX;         [/b]
   F32 steeringRollForce;

**Most of what I have added is just adding Y to the end of the stering force stuff then copying it and adding an X instead.

Next is the Flyingvehicle.cc
FlyingVehicleData::FlyingVehicleData()
{
   maneuveringForce = 0;
   horizontalSurfaceForce = 0;
   verticalSurfaceForce = 0;
   autoInputDamping = 1;   [b]
   //Edit BSK 03-05-06--------
   steeringForceY = 1;
   steeringForceX = 1;
   //-------------------------  [/b]
   steeringRollForce = 1;....................

Now scroll down to line 161
addField("autoInputDamping", TypeF32, Offset(autoInputDamping, FlyingVehicleData)); [b]
   addField("steeringForceY", TypeF32, Offset(steeringForceY, FlyingVehicleData));
   addField("steeringForceX", TypeF32, Offset(steeringForceX, FlyingVehicleData));  [/b]
   addField("steeringRollForce", TypeF32, Offset(steeringRollForce, FlyingVehicleData));

goto Line 206
stream->write(autoInputDamping); [b]
   stream->write(steeringForceY);
   stream->write(steeringForceX); [/b]
   stream->write(steeringRollForce);

now line 242
stream->read(&autoInputDamping); [b]
   stream->read(&steeringForceY);
   stream->read(&steeringForceX); [/b]
   stream->read(&steeringRollForce);

Next but and last go to line 490
// Steering 
   Point2F steering;
   steering.x = mSteering.x / mDataBlock->maxSteeringAngle;
   steering.x *= mFabs(steering.x);
   steering.y = mSteering.y / mDataBlock->maxSteeringAngle;
   steering.y *= mFabs(steering.y); [b]
   //Edited BSK 03-05-06 ------------------
   torque -= xv * steering.y * mDataBlock->steeringForceY;
   torque -= zv * steering.x * mDataBlock->steeringForceX;
   //-------------------------------------- [/b]

Ok now inside your flying vehicle scripts instead of using just steeringforce
You can use steeringForceY for up and down
and SteeringForceX for the side to side movement

to test it I set the SteeringForceX to 200 and the Y to 6500
....And to much of my surprise it worked the jet would pitch extremely well but was terrible and moving side to side.........

Well thats It....Enjoy
#2
03/03/2006 (5:24 am)
...bookmarked.... Thanks!

-Tim
#3
03/03/2006 (5:33 am)
I'd suggest still capping your actual maximum speed though, because in reality, vehicles definitely DO have a maximum speed, which is an equation of thrust vs drag (as the code above shows).

Better to tweak it to allow the speeds you want, than to remove the top speed entirely.. unless you want to reach some kind of lightspeed and flip your values.
#4
03/03/2006 (9:05 am)
@Phil
I'm working on a different way to cap the speed, I have implemented a maxFlyingSpeed before, but I want a different equation for that something that would limit the players speed a little better based off of the drag and a user defined speed. I don't know do you think that would work?

Light Speed that would be cool


--edit--
I was looking around and most of the equations you can find on the
internet take in alot more than just the thrust (maneuveringforce) and drag.
These guys take in account for wheights, torque on the engines,
and a whole bunch of stuff.
--but would that be advisable in a game?
#5
03/03/2006 (9:54 am)
Brian,

I haven't tried the speed fix yet, but the terrain collision solution seems to be working great.

Thank you for this very helpful resource.

Aaron E.
#6
03/04/2006 (1:03 pm)
Awesome!

Brian, you have managed to fix something that has been an annoyance since I purchased Torque! And it was so easy to implement that even a relative noob like myself could get it to work.

I noticed one discrepancy between the code listed above and the code that I saw in Flyingvehicle.cc. I
#7
03/04/2006 (7:29 pm)
Wow thats strange,
Thats weird, I'm using the 1.4 build and i copied that directly from code.
Well if it works thats great.

Now to Implement a max speed
#8
03/10/2006 (2:00 pm)
Thanks for posting this! worked very nicely
#9
03/18/2006 (8:32 pm)
Quote:
collisionTol = 1;
contactTol = 1;

Thank you!!!
#10
03/21/2006 (7:47 am)
So does this work with 1.4 ?
#11
03/21/2006 (4:43 pm)
Yes,
This does work with 1.4, and it works very well
#12
03/21/2006 (7:33 pm)
I have this working in 1.4 and TSE. =) It's too simple not to work I think. Now if I could figure out how to keep my flying vehicles from dancing around when I'm not flying them... there must be a way to keep the little buggers still when they're supposed to be parked.
#13
03/22/2006 (5:21 am)
Cool Well I wont need them to be parked as I am trying to make a Starfox Clone
#14
03/22/2006 (1:13 pm)
Try changing the maxautospeed stuff,

thats where the plane will turn straight and start to fall really slowly

thats how the 1.4 is i'm not sure about TSE though is it the same code

edit::

Oh ya i figured out that you should have your hover distance and your create hover height above the collision distance and tolerance, or else the plane just stops and doesn't do anything.

:)
#15
03/26/2006 (2:23 pm)
so,

it sounds like you can just dynamically change these two values when parked and it will fix the dancing problem. Interesting.

Thanks for the fix. Really handy bit of code there.