Helicopter Resource
by Tim Heldna · 11/27/2005 (10:51 pm) · 182 comments
Download Code File
Helicopter Resource
Updated March 8th 2006
This resource will implement a new vehicle class named 'helivehicle'. As the name suggests it is a helicopter resource and does not try to emulate the physics of a real helicopter, rather just the basic flight movements.
The new heliVehicle class is derived from the flyingVehicle class, therefore all functions / effects that are available to a flying vehicle are available to a heliVehicle.
The helicopter seats two people and takes damage. Light smoke will trail from the helicopter when it is partly damaged, heavier smoke when close to being destroyed and it will explode and delete when destroyed.
The helicopter has three weapons mounted to it. Two miniguns which fire on left mouse button and one grenade launcher which fires with right mouse button. Weapons do damage, apply an impulse effect, leave decals, use projectile spread, and both have all particle fx and sounds included.
Collision has been improved a great deal, I have not yet managed to fly through terrain or any other object.
The zip file below contains all head code, scripts, models, textures, particles, sounds etc that you'll need. Disregard all other links to zips on this page. The sounds contained within ARE NOT free for commercial use.
Installation:
Download the zip file here(7.11mb)
Head Code
From the zip file copy the following 4 files into your engine/game/vehicles directory
- vehicle.cc
- vehicle.h
- heliVehicle.cc
- heliVehicle.h
Add them to your project, recompile and you're done.
Scripts & other stuff
I forget some stuff for player.cs in the zip file. Please make sure you do step 3 below if you are just copying/pasting.
The zip file contains all the scripts that you need so you can just copy & paste into a fresh 1.4 version of Torque. If you want to merge, this is what you'll have to do...
1) Open server/scripts/game.cs and add this with the rest of them
2) Open server/scripts/commands.cs and add this to end of file
3) All changes for this step occur in server/scripts/player.cs
a) Within the Armor::onMount(%this,%obj,%vehicle,%node) function just after the first opening brace '{' add this line
4) Open client/scripts/default.bind.cs and add this under function jump(%val)
5) Open client/scripts/client.cs and add this to end of file
6) Open client/init.cs and add this with the rest of them
7) Add the following files from the zip file to your server/scripts directory
- heli.cs
- vehicle.cs
- chaingun.cs
- rocket_launcher.cs
8) Add the following files from the zip file to your client/scripts directory
- heliDriverMap.cs
- heliPassengerMap.cs
9) Add the following three folders from the zip file to your data/shapes directory
- iroquis
- chaingun
- rocket_launcher
10) Go into client/scripts and delete the config.cs file, otherwise your new helicopter bindings won't take effect.
Run the game, use the mission editor to drop a helicopter into your world, fly away and send Kork into orbit. Try not to manipulate or move the helicopter around too much in editor mode, especially if you're in it.
Default Controls:
w - move forward
s - move backward
a - hover up
d - hover down
m - mount / dismount helicopter
q - change seats
left mouse button - fire miniguns
right mouse button - fire rocket launcher
Known Problems:
- Doesn't like to compile in .net compilers. Your helicopter has a constant force of gravity which means you may get stuck in the terrain. Compile in vc6 if you can and you won't have any problems.
This resource is a work in progress, it's not yet up to my standards and will be improved on over time.
Here's a video of the helicopter in action
Video(12mb)
Credit and thanks to Mike Stoddart for his excellent Vehicle Resource
All comments, feedback, suggestions for improvement are welcome.
Helicopter Resource
Updated March 8th 2006
This resource will implement a new vehicle class named 'helivehicle'. As the name suggests it is a helicopter resource and does not try to emulate the physics of a real helicopter, rather just the basic flight movements.
The new heliVehicle class is derived from the flyingVehicle class, therefore all functions / effects that are available to a flying vehicle are available to a heliVehicle.
The helicopter seats two people and takes damage. Light smoke will trail from the helicopter when it is partly damaged, heavier smoke when close to being destroyed and it will explode and delete when destroyed.
The helicopter has three weapons mounted to it. Two miniguns which fire on left mouse button and one grenade launcher which fires with right mouse button. Weapons do damage, apply an impulse effect, leave decals, use projectile spread, and both have all particle fx and sounds included.
Collision has been improved a great deal, I have not yet managed to fly through terrain or any other object.
The zip file below contains all head code, scripts, models, textures, particles, sounds etc that you'll need. Disregard all other links to zips on this page. The sounds contained within ARE NOT free for commercial use.
Installation:
Download the zip file here(7.11mb)
Head Code
From the zip file copy the following 4 files into your engine/game/vehicles directory
- vehicle.cc
- vehicle.h
- heliVehicle.cc
- heliVehicle.h
Add them to your project, recompile and you're done.
Scripts & other stuff
I forget some stuff for player.cs in the zip file. Please make sure you do step 3 below if you are just copying/pasting.
The zip file contains all the scripts that you need so you can just copy & paste into a fresh 1.4 version of Torque. If you want to merge, this is what you'll have to do...
1) Open server/scripts/game.cs and add this with the rest of them
// Heli Resource Code Start //
exec("./heli.cs");
exec("./vehicle.cs");
exec("./chaingun.cs");
exec("./rocket_launcher.cs");
// Heli Resource Code End //2) Open server/scripts/commands.cs and add this to end of file
// 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 //3) All changes for this step occur in server/scripts/player.cs
a) Within the Armor::onMount(%this,%obj,%vehicle,%node) function just after the first opening brace '{' add this line
onPlayerMount(%this,%obj,%vehicle,%node);b) Within the Armor::onUnmount( %this, %obj, %vehicle, %node ) function after the first opening brace '{' add this line
onPlayerUnmount(%this, %obj, %vehicle, %node);c) Within the Armor::doDismount(%this, %obj, %forced) function after the first opening brace '{' add this line
doPlayerDismount(%this, %obj, %forced);
4) Open client/scripts/default.bind.cs and add this under function jump(%val)
// Heli Resource Code Start //
function mouseJet(%val)
{
$mvTriggerCount3++;
}
function mouseJetdn(%val)
{
$mvTriggerCount4++;
}
moveMap.bindCmd(keyboard, "m", "commandToServer('MountVehicle');", "");
// Heli Resource Code End //5) Open client/scripts/client.cs and add this to end of file
// 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 //6) Open client/init.cs and add this with the rest of them
// Heli Resource Code Start //
exec("./scripts/heliDriverMap.cs");
exec("./scripts/heliPassengerMap.cs");
// Heli Resource Code End //7) Add the following files from the zip file to your server/scripts directory
- heli.cs
- vehicle.cs
- chaingun.cs
- rocket_launcher.cs
8) Add the following files from the zip file to your client/scripts directory
- heliDriverMap.cs
- heliPassengerMap.cs
9) Add the following three folders from the zip file to your data/shapes directory
- iroquis
- chaingun
- rocket_launcher
10) Go into client/scripts and delete the config.cs file, otherwise your new helicopter bindings won't take effect.
Run the game, use the mission editor to drop a helicopter into your world, fly away and send Kork into orbit. Try not to manipulate or move the helicopter around too much in editor mode, especially if you're in it.
Default Controls:
w - move forward
s - move backward
a - hover up
d - hover down
m - mount / dismount helicopter
q - change seats
left mouse button - fire miniguns
right mouse button - fire rocket launcher
Known Problems:
- Doesn't like to compile in .net compilers. Your helicopter has a constant force of gravity which means you may get stuck in the terrain. Compile in vc6 if you can and you won't have any problems.
This resource is a work in progress, it's not yet up to my standards and will be improved on over time.
Here's a video of the helicopter in action
Video(12mb)
Credit and thanks to Mike Stoddart for his excellent Vehicle Resource
All comments, feedback, suggestions for improvement are welcome.
About the author
Recent Blogs
• BCS Street props• Character Pack - Vince
• Recent Artwork
• Progress of our Weapon Pack
• Digital Speedometer
Torque 3D Owner Michael Canty
I am trying to get this resource into T3D. I have it working but my FPS is down to 12. Any ideas.
Edit:
Nevernind, I just had to look at the packetupdate and the coollision code. Woriks fine now.