Game Development Community

Jetting III w/ Air Control or Flying

by Quest Johnny · in Torque Game Engine · 08/17/2004 (6:24 am) · 0 replies

Again, this is a simple trick that I'm sharing. I happened across it last night.
I implementing both of the Jetting resources, and I currenly have Sam Guffey's Jetting in place. This change will allow your player to control his direction as well as rising while jetting, a bit like flight or a jetpack.

Method:

Step One:
Implement Sam Guffey's Jetting control. This causes your chr to rise into the air (vertically) when you jet.

Step Two: Borrowed from the "Easy Swimming" resouce, add the following lines to your player.cc:

In the block which begins:
//JETTING II
// Are we using the Jets or not?
if(!mJetting)
{
if (mJetSound) {
alxStop(mJetSound);
Right under where acc.z is set, add:
//try to call script too?
Con::executef(mDataBlock,3,"flap",scriptThis());
//end
Before the lines:
if (mDataBlock->sound[PlayerData::JetSound])
{
if (!mJetSound)
mJetSound = alxPlay(mDataBlock->sound[PlayerData::JetSound], &getTransform());

Step Three:
This change calls a script function in the middle of jetting, I used the following in my tests:
function Armor::flap(%this, %obj)
{
echo("you r flapping"); //you bet he is!!
%position = %obj.getTransform();
%pos = getWords(%position, 0, 2);
%eye = %obj.getEyeVector();

%xx = getWord(%eye, 0) * 1.3;
%yy = getWord(%eye, 1) * 1.3;
%zz = getWord(%eye, 2) * 1.3;

%vec = (%xx SPC %yy SPC %zz);

%obj.applyImpulse(%pos, VectorScale(%vec, %obj.getDataBlock().mass));
}//endF

And your players will now be able to fly whichever way they point while jetting. I have not testing this in multiplayer, but it works fine dedicated. To really be complete, I probably need to add a water detection, so that you jet underwater only if the game-designer has said you can, and I'd also like a maximum altitude attribute.

Note that this is compatible with the Easy Swimming resource.

There is also the very good Air Control resource for a more complete solution.

Hope this helps, -LL2