Helicopter, Helicopter, Pilot Man....
by Sean Rice · 03/31/2010 (9:56 am) · 36 comments
A few edits, added the full helicopter files for T3D 1.0 as drag and drop. Install a fresh copy and drop this over the top, add the two engine files and recompile. You will be able to add the helicopter after that. Original work and credits go to www.torquepowered.com/community/resource/view/9263/
www.dropbox.com/s/oimplfcjbb5jyof/helicopter-t3d.rar Full helicopter source and all files for T3D.
Edit source/T3D/vehicle.cpp
after
add
after
add
after
add
after
add
Now edit, vehicle.h
after
add
Pulling a bit of code from www.torquepowered.com/community/resources/view/9263/4#comment-51506 seems to have fixed the at rest stuck issue. You can embed the heli in the terrain and it will fly away like it wasn't. This was the simpliest code to insert and seems to work very well. I am not sure of any far reaching implications with the usage of this.
In vechile.cpp find the function for
void Vehicle::updatePos(F32 dt)
Add the helicopter code into the engine and recompile.
Edit, game/scripts/client/client.cs and at the bottom of this file paste this,
Edit scripts/client/default.bind.cs and place this at the bottom
Edit scripts/cleint/init.cs and before
insert
Now edit scripts/server/commands.cs and at the end of the file add
Now, it player.cs replace your Armor::OnMount and Armor::OnUnMount functions with these. This will bind the action maps and should provide the correct flight functionality.
Now copy over the art and script files in the folder. The scripts are a little issue, there are some T3D scripts that cover the same functions. Let's get the engine in now before going through the scripts.
When your done, you should be able to have something similar to this below. You will notice, I get into it while it is above the ground. It gets 's stuck at this moment in the ground. There are multiple fixes that will be tested on this resource until we resolve this issue with it.
www.dropbox.com/s/oimplfcjbb5jyof/helicopter-t3d.rar Full helicopter source and all files for T3D.
Edit source/T3D/vehicle.cpp
after
mJetting = false;
add
mJettingDn = false;
after
// Jetting flag
if (move->trigger[3]) {
if (!mJetting && getEnergyLevel() >= mDataBlock->minJetEnergy)
mJetting = true;
if (mJetting) {
F32 newEnergy = getEnergyLevel() - mDataBlock->jetEnergyDrain;
if (newEnergy < 0) {
newEnergy = 0;
mJetting = false;
}
setEnergyLevel(newEnergy);
}
}
else
mJetting = false;add
// Jetting flag Heli
if (move->trigger[4]) {
if (!mJettingDn && getEnergyLevel() >= mDataBlock->minJetEnergy)
mJettingDn = true;
if (mJettingDn) {
F32 newEnergy = getEnergyLevel() - mDataBlock->jetEnergyDrain;
if (newEnergy < 0) {
newEnergy = 0;
mJettingDn = false;
}
setEnergyLevel(newEnergy);
}
}
else
mJettingDn = false;after
stream->writeFlag(mJetting);
add
stream->writeFlag(mJettingDn);
after
mJetting = stream->readFlag();
add
mJettingDn = stream->readFlag();
Now edit, vehicle.h
after
bool mJetting;
add
bool mJettingDn;
Pulling a bit of code from www.torquepowered.com/community/resources/view/9263/4#comment-51506 seems to have fixed the at rest stuck issue. You can embed the heli in the terrain and it will fly away like it wasn't. This was the simpliest code to insert and seems to work very well. I am not sure of any far reaching implications with the usage of this.
In vechile.cpp find the function for
void Vehicle::updatePos(F32 dt)
Point3F origVelocity = mRigid.linVelocity;
// Update internal forces acting on the body.
mRigid.clearForces();
updateForces(dt);
[b]
// Integrate forward
if (!mRigid.atRest)
mRigid.integrate(dt);
[/b]
// Update collision information based on our current pos.
bool collided = false;
if (!mRigid.atRest) {
collided = updateCollision(dt);
// Now that all the forces have been processed, lets
// see if we're at rest. Basically, if the kinetic energy of
// the vehicles is less than some percentage of the energy added
// by gravity for a short period, we're considered at rest.
// This should really be part of the rigid class...
if (mCollisionList.count) {
F32 k = mRigid.getKineticEnergy();
F32 G = sVehicleGravity * dt;
F32 Kg = 0.5 * mRigid.mass * G * G;
if (k < sRestTol * Kg && ++restCount > sRestCount)
mRigid.setAtRest();
}
else
restCount = 0;
}
[b]
// Integrate forward
//if (!mRigid.atRest)
// mRigid.integrate(dt);
[/b] Add the helicopter code into the engine and recompile.
Edit, game/scripts/client/client.cs and at the bottom of this file paste this,
// Heli Resource Code Start //
//----------------------------------------------------------------------------
// Vehicle commands
//----------------------------------------------------------------------------
function clientCmdPopActionMap()
{
echo("Popping Player action map " );
movemap.pop();
}
function clientCmdPushActionMap()
{
echo("Pushing Player action map " );
movemap.push();
}
//----------------------------------------------------------------------------
function clientCmdPopActionMapHelicopterDriver()
{
echo("Popping Helicopter Driver action map " );
heliDriverMap.pop();
}
function clientCmdPopActionMapHelicopterPassenger()//%vehicleType
{
echo("Popping Helicopter Passenger action map " );
heliPassengerMap.pop();
}
//----------------------------------------------------------------------------
function clientCmdPushActionMapHelicopterDriver()
{
echo("Pushing Helicopter Driver action map " );
heliDriverMap.push();
}
function clientCmdPushActionMapHelicopterPassenger()
{
echo("Pushing Helicopter Passenger action map " );
heliPassengerMap.push();
}
// Heli Resource Code End //Edit scripts/client/default.bind.cs and place this at the bottom
// Heli Resource Code Start //
function mouseJet(%val)
{
$mvTriggerCount3++;
}
function mouseJetdn(%val)
{
$mvTriggerCount4++;
}
moveMap.bindCmd(keyboard, "m", "commandToServer('MountVehicle');", "");
// Heli Resource Code End //Edit scripts/cleint/init.cs and before
loadMaterials();
insert
// Heli Resource Code Start // exec("./heliDriverMap.cs"); exec("./heliPassengerMap.cs"); // Heli Resource Code End //
Now edit scripts/server/commands.cs and at the end of the file add
// Heli Resource Code Start //
function serverCmdMountVehicle(%client)
{
//Determine how far should the picking ray extend into the world?
%selectRange = 3;
// Only search for vehicles
%searchMasks = $TypeMasks::vehicleObjectType;
%pos = %client.player.getEyePoint();
// Start with the shape's eye vector...
%eye = %client.player.getEyeVector();
%eye = vectorNormalize(%eye);
%vec = vectorScale(%eye, %selectRange);
%end = vectorAdd(%vec, %pos);
%scanTarg = ContainerRayCast (%pos, %end, %searchMasks);
// a target in range was found so select it
if (%scanTarg)
{
%targetObject = firstWord(%scanTarg);
echo("Found a vehicle: " @ %targetObject);
onMountVehicle(%targetObject.getDataBlock(),
%client.player,
%targetObject);
}
else
{
echo("No object found");
}
}
function serverCmdDismountVehicle(%client)
{
doPlayerDismount(%client, %client.player, %true);
}
function serverCmdFindNextFreeSeat(%client)
{
echo("serverCmdFindNextFreeSeat " @ %client.nameBase);
// Is the vehicle moving? If so, prevent the player from switching seats
if (isVehicleMoving(%client.player.mvehicle) == true)
return;
%newSeat = findNextFreeSeat(%client,
%client.player.mvehicle,
%client.player.mvehicle.getDataBlock());
if (%newSeat != -1)
{
echo("Found new seat " @ %newSeat);
setActiveSeat(%client.player,
%client.player.mvehicle,
%client.player.mvehicle.getDataBlock(),
%newSeat);
}
else
{
echo("No next free seat");
}
}
// Heli Resource Code End //Now, it player.cs replace your Armor::OnMount and Armor::OnUnMount functions with these. This will bind the action maps and should provide the correct flight functionality.
function Armor::onMount(%this, %obj, %vehicle, %node)
{
// Node 0 is the pilot's position, we need to dismount his weapon.
if (%node == 0)
{
%obj.setTransform("0 0 0 0 0 1 0");
%obj.setActionThread(%vehicle.getDatablock().mountPose[%node], true, true);
%obj.lastWeapon = %obj.getMountedImage($WeaponSlot);
%obj.unmountImage($WeaponSlot);
%obj.setControlObject(%vehicle);
//%obj.client.setObjectActiveImage(%vehicle, 2);
CommandToClient(%obj.client, 'PopActionMap', moveMap);
CommandToClient(%obj.client, 'PushActionMapHelicopterDriver',heliDriverMap);
}
else
{
if (%vehicle.getDataBlock().mountPose[%node] !$= "")
%obj.setActionThread(%vehicle.getDatablock().mountPose[%node]);
else
%obj.setActionThread("root", true);
CommandToClient(%client, 'PopActionMap', moveMap);
CommandToClient(%client, 'PushActionMap', $Vehicle::moveMaps[%seat]);
}
}
function Armor::onUnmount(%this, %obj, %vehicle, %node)
{
%obj.setActionThread("run", true, true);
if (%node == 0)
{
%obj.mountImage(%obj.lastWeapon, $WeaponSlot);
%obj.setControlObject("");
}
CommandToClient(%obj.client, 'PopActionMapHelicopterDriver', heliDriverMap);
CommandToClient(%obj.client, 'PopActionMapHelicopterPassenger', heliPassengerMap);
CommandToClient(%obj.client, 'PushActionMap', moveMap);
}Now copy over the art and script files in the folder. The scripts are a little issue, there are some T3D scripts that cover the same functions. Let's get the engine in now before going through the scripts.
When your done, you should be able to have something similar to this below. You will notice, I get into it while it is above the ground. It gets 's stuck at this moment in the ground. There are multiple fixes that will be tested on this resource until we resolve this issue with it.
About the author
http://www.hngamers.com
#2
03/31/2010 (1:43 pm)
Nice! I also ported the heli resource for some time ago to T3D but end up with the "stuck in ground". Did you manage to fix this issue?
#3
@Stefan, lol!
03/31/2010 (1:53 pm)
Not 100% sure at this time, I'm down to flight controls to actually be able to fly it. I have been splitting my time with website disaster and the FGE/3DISO ports. So far, I haven't seen any issue with sticking during the tests I have done short of flying. Does the sticking extend to editing the level as well, IE the helicopter spawns slightly under ground and you cannot remove it? So far, I have been able to move them, shoot them and have them bounce off of the terrain. I am pretty sure I remembered seeing a "fix" for the issue, if it does rear it's head I will hunt it out. @Stefan, lol!
#4
03/31/2010 (1:54 pm)
BTW, does anyone have the other part of the this resource? The guns/other mounting points? This is the original helicopter, I want to get it all working.
#5
03/31/2010 (2:00 pm)
Quote:Does the sticking extend to editing the level as well, IE the helicopter spawns slightly under ground and you cannot remove it?Nahh, it had something to do with .net compilers(read "known problems"), but maybe this isn't based on that resource... Is it?
#6
03/31/2010 (2:11 pm)
Nope, thats the resource, I need to put the credits up for it. I did compile this in .net, do we have another choice? I thought the only issue was the slow loss of height due to the gravitational pull that wasn't quite done right in .net?
#7
I dunno, but i did try the heli resource both in TGE, TGEA and T3D (VC 2008) and all resulted with "stuck in ground" issue, but if you don't experience this issue with your port i will try it out.
03/31/2010 (3:22 pm)
Quote:I thought the only issue was the slow loss of height due to the gravitational pull that wasn't quite done right in .net?
I dunno, but i did try the heli resource both in TGE, TGEA and T3D (VC 2008) and all resulted with "stuck in ground" issue, but if you don't experience this issue with your port i will try it out.
Quote:I did compile this in .net, do we have another choice?Not really =/.
#8
must have been half asleep when I posted this. I think I ported this to TGEA. I increased the gravity / bounce to stop the heli from going into the ground by doing a raycast (or something along those lines). Looking good Sean.
03/31/2010 (11:58 pm)
edit:must have been half asleep when I posted this. I think I ported this to TGEA. I increased the gravity / bounce to stop the heli from going into the ground by doing a raycast (or something along those lines). Looking good Sean.
#9
04/01/2010 (6:13 am)
Ok, so it looks like it is definitely sticking in the ground. The Heli works great other then that, I will package this the rest of the way up and get it on here. There are quite a few "fixes" for this issue, I will begin going through them to try and minimize this issue.
#11
04/01/2010 (6:50 am)
The explosions and sounds have been commented out in this. You will need to edit the heli.cs file and uncomment (and replace the explosions and sound files) for correct explosions.
#12
04/01/2010 (7:43 am)
Does the heli fly realistically, or is it just using the Flying Vehicle physics? I remember finding a way to tell it to apply force downward, so you would have to tilt the chopper forward to move forward, applying more power to balance the loss of lift...I'll try to track that change down. But no matter. Good job porting these resources, you're doing a great thing for the community!
#13
BTW. are you using the heli resource in your demo? Or did you make your own class?
@ Sean, seeing your updated video, you know that the A and D key is supposed to make the heli hover up/down? Unfortunately i don't know/remember the fix, but i think i found the solution in the original resource's comments once. And BTW. weren't you looking for the chaingun files, cuz i know that some of these guys have it.
04/01/2010 (8:01 am)
@ bryceQuote:Does the heli fly realistically, or is it just using the Flying Vehicle physics?It's the Flying Vehicle physics =/.
Quote:I remember finding a way to tell it to apply force downwardwow, that would've been awesome if someone integrated.
BTW. are you using the heli resource in your demo? Or did you make your own class?
@ Sean, seeing your updated video, you know that the A and D key is supposed to make the heli hover up/down? Unfortunately i don't know/remember the fix, but i think i found the solution in the original resource's comments once. And BTW. weren't you looking for the chaingun files, cuz i know that some of these guys have it.
#14
04/01/2010 (8:59 am)
@Marcus, yeah I was doing some more work in it and found I had accidentally reverted that after I had submitted the updates. I had it working before the revert :/ I will figure it out and post the fixes.
#15
04/01/2010 (12:19 pm)
Updated top post with Action map binding and a two line change in code that seems to have resolved the, on the ground stuck issue. I embedded a couple of heli's it the terrain and was able to fly away without an issue. I will update the videos with the new changes.
#16
04/01/2010 (3:42 pm)
Cool, Apache fights!... thanks....
#17
Type "plane" into the console on that demo, you'll get a chopper with the realistic flight. You'll have to gain a lot of vertical speed to break the auto stabilize, but once you're going upward fast enough, tilt it forward and enjoy the flight!
Found that fix, by the way. Find this section in flyingVehicle.cc:
And replace it with
Force is now applied vertically. It takes some getting used to, be warned.
04/01/2010 (7:30 pm)
@Marcus: The AI helicopter doesn't use physics, it's a dumb, pathed NPC that is set to not be affected by gravity. Shoot it through a scope, it even bleeds :pType "plane" into the console on that demo, you'll get a chopper with the realistic flight. You'll have to gain a lot of vertical speed to break the auto stabilize, but once you're going upward fast enough, tilt it forward and enjoy the flight!
Found that fix, by the way. Find this section in flyingVehicle.cc:
// Maneuvering jets force += yv * (mThrust.y * mDataBlock->maneuveringForce * mCeilingFactor); force += xv * (mThrust.x * mDataBlock->maneuveringForce * mCeilingFactor);
And replace it with
// Maneuvering jets force += zv * (mThrust.y * mDataBlock->maneuveringForce * mCeilingFactor);
Force is now applied vertically. It takes some getting used to, be warned.
#19
Thanks BAG, onto FACK and MACK soon ;)
04/04/2010 (4:27 pm)
@Bryce, I did not seem to notice too much of a change with that specific set there. Everything seemed to be exactly the same afterwards, any script changes? Thanks BAG, onto FACK and MACK soon ;)
#20
04/04/2010 (11:03 pm)
@Sean: No script changes. That snippet tells the engine to use the force applied using the forward/backward (W/S) keys on the Z-axis, so power is applied downward. This requires you to tilt the vehicle and apply power for it to move forward, while sacrificing some lift. Here's my datablock if it helps:datablock FlyingVehicleData(Helicopter)
{
spawnOffset = "0 0 2";
emap = true;
category = "Vehicles";
shapeFile = "~/data/shapes/statics/vehicles/hip1_driveable.dts";
multipassenger = false;
computeCRC = true;
debrisShapeName = "~/data/shapes/buggy/buggy.dts";
//debrisShapeName = "~/data/shapes/airliner/plane.dts";
debris = PlaneExplosionDebris;
renderWhenDestroyed = false;
drag = 0.25;
density = 1.0;
// Mounting Details
numMountPoints = 1; // How many mount points you want.
multipassenger = false; // Depends on # of mountpoints.
maxMountSpeed = 0.1;
mountDelay = 8;
dismountDelay = 1;
stationaryThreshold = 0.5;
maxDismountSpeed = 0.1;
mountPose[0] = "Sitting";
mountPointTransform[0] = "0 0 0 0 0 1 0";
isProtectedMountPoint[0] = true;
isProtectedMountPoint[1] = true;
minMountDist = 2;
mountPose[0] = sitting; // This is the possition linked to the animation
mountable = true;
// Camera Settings
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraMaxDist = 16;
cameraOffset = 3.65;
cameraLag = 0.1;
cameraRoll = true; // Roll the camera with the vehicle
// Explosions = FighterVehicleExplosion; // Particle Data?
explosionDamage = 10.5;
explosionRadius = 15.0;
maxDamage = 10e20;
disabledLevel = 0.75;
destroyedLevel = 1.0;
// Afterburner and any energy weapon pool
energyPerDamagePoint = 160;
maxEnergy = 280;
rechargeRate = 0.8;
minDrag = 10; // Linear Drag (eventually slows you down when not thrusting...constant drag)
rotationalDrag = 20; // Anguler Drag (dampens the drift after you stop moving the mouse...also tumble drag)
maxAutoSpeed = 1; // Autostabilizer kicks in when less than this speed. (meters/second)
autoAngularForce = 500; // Angular stabilizer force (this force levels you out when autostabilizer kicks in)
autoLinearForce = 500; // Linear stabilzer force (this slows you down when autostabilizer kicks in)
autoInputDamping = 0.55; // Dampen control input so you don't' whack out at very slow speeds
// Maneuvering
maxSteeringAngle = 2; // Max radiens you can rotate the wheel. Smaller number is more maneuverable.
horizontalSurfaceForce = 40; // Horizontal center "wing" (provides "bite" into the wind for climbing/diving and turning)
verticalSurfaceForce = 20; // Vertical center "wing" (controls side slip. lower numbers make MORE slide.)
maneuveringForce = 2000; // Horizontal jets (W,S,D,A key thrust) was 3000
steeringForce = 1000; // Steering jets (force applied when you move the mouse)
steeringRollForce = 2000; // Steering jets (how much you heel over when you turn)
rollForce = 20; // Auto-roll (self-correction to right you after you roll/invert)
hoverHeight = 2; // Height off the ground at rest
createHoverHeight = 1; // Height off the ground when created
maxForwardSpeed = 90; // speed in which forward thrust force is no longer applied (meters/second)
// Turbo Jet
jetForce = 3000; // Afterburner thrust (this is in addition to normal thrust)
minJetEnergy = 28; // Afterburner can't be used if below this threshhold.
jetEnergyDrain = 2.8; // Energy use of the afterburners (low number is less drain...can be fractional) // Auto stabilize speed
vertThrustMultiple = 3.0;
// Rigid body
mass = 100; // Mass of the vehicle
integration = 3; // Physics integration: TickSec/Rate
collisionTol = 0.6; // Collision distance tolerance
contactTol = 0.4; // Contact velocity tolerance
bodyFriction = 0; // Don't mess with this.
bodyRestitution = 0.8; // When you hit the ground, how much you rebound. (between 0 and 1)
minRollSpeed = 2000; // Don't mess with this.
softImpactSpeed = 3; // Sound hooks. This is the soft hit.
hardImpactSpeed = 15; // Sound hooks. This is the hard hit.
// Ground Impact Damage (uses DamageType::Ground)
minImpactSpeed = 2; // If hit ground at speed above this then it's an impact. Meters/second
damageMul = 20;
// Object Impact Damage (uses DamageType::Impact)
collDamageThresholdVel = 23.0;
collDamageMultiplier = 0.02;
// Contrails
minTrailSpeed = 1500; // The speed your contrail shows up at.
trailEmitter = FighterContrailEmitter;
forwardJetEmitter = FighterFJetEmitter;
downJetEmitter = FighterDJetEmitter;
checkRadius = 5.5;
observeParameters = "0 0 1";
shieldEffectScale = "0.937 1.125 0.60";
}; 
Torque Owner Shaderman
Thanks for sharing all these resources!