Game Development Community

dev|Pro Game Development Curriculum

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
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.



Page«First 1 2 Next»
#21
04/05/2010 (6:48 am)
I see I'm not the only person who sticks in "//don't mess with this" comments incase he forgets. ;)
#22
06/04/2010 (1:36 pm)
This is just what I need to make my Stargate Puddle Jumper Fly! Ill let you know how it works out, I am not sure i see where i pout, and how to call the engine files, but I know the location of which you speak in your explanation...I will probably need help, I hope you still check this:O)
#23
08/15/2010 (1:40 pm)
Has anybody had luck getting this to work with 1.1beta 2? I am having errors when I try to recompile the source code.

1>------ Build started: Project: Island DLL, Configuration: Debug Win32 ------
1>Compiling...
1>wheeledVehicle.cpp
1>vehicle.cpp
1>hoverVehicle.cpp
1>heliVehicle.cpp
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(89) : warning C4305: '=' : truncation from 'double' to 'F32'
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(147) : error C2065: 'TypeSFXProfilePtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(148) : error C2065: 'TypeSFXProfilePtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(164) : error C2065: 'TypeParticleEmitterDataPtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(165) : error C2065: 'TypeParticleEmitterDataPtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(166) : error C2065: 'TypeParticleEmitterDataPtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(167) : error C2065: 'TypeParticleEmitterDataPtr' : undeclared identifier
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(293) : error C2660: 'Vehicle::onNewDataBlock' : function does not take 1 arguments
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\helivehicle.cpp(656) : error C2660: 'ParticleEmitter::onNewDataBlock' : function does not take 1 arguments
1>guiSpeedometer.cpp
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\vehicle.cpp(1026) : error C2059: syntax error : 'if'
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\vehicle.cpp(1026) : error C2143: syntax error : missing ';' before '{'
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\vehicle.cpp(1026) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\torque\torque 3d 2009 pro 1.1 beta 2\engine\source\t3d\vehicles\vehicle.cpp(1038) : error C2059: syntax error : 'else'
1>flyingVehicle.cpp
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 9.00.30729
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\Torque\Torque 3D 2009 Pro 1.1 Beta 2\My Projects\Island\buildFiles\Link\VC2k8.Debug.Win32\Island DLL\BuildLog.htm"
1>Island DLL - 12 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 16 up-to-date, 0 skipped ==========
#24
10/12/2010 (6:38 pm)
Updated top resource with the original build files (including the original helicopter resource this came from and all art files, mini guns and rocket launchers) to resolve a file front uploaded file issue.
#25
03/31/2011 (1:50 am)
Port for T3D 1.1 Beta 3
I did some quick tests, but i'm not sure that everything works fine.
Complete files HERE


The major changes, as well as a few small changes in the sources, are mainly these:

On scripts/server/scriptExec.cs add:
exec("./vehicleHeli.cs");

On art/datablocks/datablockExec.cs add:
exec("./vehicles/defaultHeli.cs");

On tools/worldEditor/gui/objectBuilderGui.ed.gui, after this:
(around line 1080)
function HoverVehicleData::create(%block)
{
   %obj = new HoverVehicle()
   {
      dataBlock = %block;
      parentGroup = EWCreatorWindow.objectGroup;
   };
   return(%obj);
}

Add:
function HeliVehicleData::create(%block)
{
   %obj = new HeliVehicle() {
      dataBlock = %block;
      parentGroup = EWCreatorWindow.objectGroup;
   };
   return %obj;
}

On scripts/server/player.cs, change this:
(required for the mount)
// Mount vehicles
   if (%col.getType() & $TypeMasks::GameBaseObjectType)
   {
      %db = %col.getDataBlock();
      if ((%db.getClassName() $= "WheeledVehicleData") && %obj.mountVehicle && %obj.getState() $= "Move" && %col.mountable)
      {

To this:
// Mount vehicles
   if (%col.getType() & $TypeMasks::GameBaseObjectType)
   {
      %db = %col.getDataBlock();
      if ((%db.getClassName() $= "WheeledVehicleData" || %db.getClassName() $= "heliVehicleData") && %obj.mountVehicle && %obj.getState() $= "Move" && %col.mountable)
      {
#26
05/10/2011 (4:50 am)
Alfio Saitta your code has worked fine with T3d.
but there is a problem.it gives this error:

Found a vehicle: 8789
scripts/server/commands.cs (131): Unable to find function onMountVehicle

my trail solution was this:

in commands.cs there is
function serverCmdMountVehicle(%client).
in which there is a line:

onMountVehicle(%targetObject.getDataBlock(),%client.player,%targetObject);

but there is no defination for onMountVehicle().

so in server->vehicle.cs u have to add :


$Vehicle::moveMaps[0] = "heliDriverMap";
$Vehicle::moveMaps[1] = "heliPassengerMap";
$Vehicle::moveMaps[2] = "heliPassengerMap";
$Vehicle::moveMaps[3] = "heliPassengerMap";
$Vehicle::moveMaps[4] = "heliPassengerMap";

function onMountVehicle(%vehicle, %obj, %col)
{
// Is the vehicle currently mountable?
if (%col.mountable == false)
{
echo("Sorry, the vehicle is not mountable.");
return;
}

// Check the speed of the vehicle. If it's moving, we can't mount it.
// Note there is a threshold that determines if the vehicle is moving.
%vel = %col.getVelocity();
%speed = vectorLen(%vel);

if ( %speed <= %vehicle.maxMountSpeed )
{
// Find an empty seat
%seat = findEmptySeat(%col, %vehicle);

%obj.mVehicle = %col;
%obj.mSeat = %seat;
%obj.isMounted = true;

echo("Mounting vehicle in seat " @ %seat);

// Now mount the vehicle.
%col.mountObject(%obj,%seat);
}
else
{
echo("You cannot mount a moving vehicle.");
}
}


it is the code that was in (server->vehicle.cs) supplied by Sean Rice in that helicopter-t3d.rar.
#27
05/10/2011 (4:54 am)
That function is in helivehicle.cs; although, it should probably be changed so that the helicopter can be mounted like any other vehicle class.


function onMountVehicle(%vehicle, %obj, %col)
{
   // Is the vehicle currently mountable?
   //if (%col.mountable != true)
   //{
   //   echo("Sorry, the vehicle is not mountable.");
   //   return;
   //}

   // Check the speed of the vehicle. If it's moving, we can't mount it.
   // Note there is a threshold that determines if the vehicle is moving.
   %vel = %col.getVelocity();
   %speed = vectorLen(%vel);

   if ( %speed <= %vehicle.maxMountSpeed )
   {
      // Find an empty seat
      %seat = findEmptySeat(%col, %vehicle);

      %obj.mVehicle = %col;
      %obj.mSeat = %seat;
      %obj.isMounted = true;

      echo("Mounting vehicle in seat " @ %seat);

      // Now mount the vehicle.
      %col.mountObject(%obj,%seat);
   }
   else
   {
      echo("You cannot mount a moving vehicle.");
   }
}
#28
05/10/2011 (5:02 am)
i was trying to apply
Vehicle Camera Mouse Control - Driving and Looking by John Eckhardt
(http://www.garagegames.com/community/resources/view/17759/).

i have tryed to change void heliVehicle::updateMove(const Move* move).but it is not working. heliVehicle::updateMove(const Move* move) is very different from Vehicle::updateMove(const Move* move).may be that is the reason.can anybody give any direction so that i can work out this configuration for control:
w->up
s->down
a->left rotate
d->right rotate

num 8->forward
num 2->backward
num 4->left
num 6->right.

this is the configuration from Grand theft auto.

#29
05/11/2011 (2:41 pm)
Anyone have the 1.1b3 source files for this?
#30
05/12/2011 (10:19 am)
Alfio - your link is dead.
#32
05/12/2011 (2:17 pm)
Alfio, I sent you email. I was wondering if you received it?
#33
05/13/2011 (8:09 am)
No =D

My current email address is: info(DOT)collateral(ET)gmail(DOT)com
#34
09/19/2012 (2:48 am)
i am having problem with engine sound.
only when heli is under water it sometimes start to play for few second.

anybody having same issue?

i have tried all other vehicles updateEngineSound().
but no luck.

here is a same type of problem.
http://www.garagegames.com/community/forums/viewthread/125077/1#comment_form

but those fix did not work
#35
10/07/2012 (6:15 am)
"i am having problem with engine sound."

solved.i will post the solution after testing against this resource.
#36
12/30/2012 (12:39 pm)
i try compile the files of Mr. Saitta with Torque 2.0 MIT but get this errors:

error C1083: Cannot open include file: 'sceneGraph/sceneState.h': No such file or directory
/Torque3D/Engine/source/T3D/vehicles/vehicle.cpp 26

error C2061: syntax error : identifier 'SceneState'
/Torque3D/Engine/source/T3D/vehicles/vehicle.h 226

error C2660: 'Vehicle::prepBatchRender' : function does not take 2 arguments
/Torque3D/Engine/source/T3D/vehicles/wheeledVehicle.cpp 1370

someone has a working updated version? thanks.


Page«First 1 2 Next»