Game Development Community

Mountable Buggy

by Samuel Harper · in Torque Game Engine · 09/30/2006 (2:03 pm) · 14 replies

In a fresh install of 1.4 TGE - is the buggy mountable by default?

#1
09/30/2006 (5:36 pm)
No, you need write the mount script for it.
#2
09/30/2006 (6:21 pm)
Speaking of the buggy, i made one that works fine in my GameOne, but when I ported it to FPS.starter I cant jump out. In my gameOne the player jumps out next to the buggy using spacebar, in fps.starter the spacebar is binded to change the camera view and the player stays in the buggy. I cant find where it does that in the code. Does anyone know where that is?
#3
09/30/2006 (7:06 pm)
Client/scripts/default.bind. If not misstake you going need add the umount code in the player.cs in server/scripts.
#4
09/30/2006 (7:26 pm)
I've looked thru that default.bind. it only has spacebar for jump. i've also added the nessasary code in player.cs. there must be some other script that is making the camera rotate. it rotates 45 degrees (or something) when mounted in the buggy when i press the spacebar. if i hold down the spacebar it rotates real fast.
#5
09/30/2006 (8:09 pm)
Add another key bind for the umount code you put in the player.cs in default.bind. The spacebar jump only work for the player when not mount to a buggy or horse. There maybe better way but this was only way I could get to work in the starter.fps. I do not know what using for your unmount code but the example work with my. If could see your code for unmount I could help more.

For example:

moveMap.bindCmd(keyboard, "ctrl x","getout();","");
#6
09/30/2006 (11:32 pm)
The starter.fps kit already has basic support for mounting, dismounting of vehicles. You will find this code inside of player.cs inside the armor functions. When mounted to a vehicle, the jump trigger is automatically bound to Armor::doDismount. The reason it doesn't work is due to a few scripting errors in player.cs.

To fix, change the following four functions inside of player.cs to read like this:
function Armor::onMount(%this,%obj,%vehicle,%node)
{
   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);
      %vehicle.mountable = false;
   }
}

function Armor::onUnmount( %this, %obj, %vehicle, %node )
{
   if (%node == 0)
      %obj.mountImage(%obj.lastWeapon, $WeaponSlot);
      %vehicle.mountable = true;
}

function Armor::doDismount(%this, %obj, %forced)
{
   // This function is called by player.cc when the jump trigger
   // is true while mounted
   if (!%obj.isMounted())
      return;

   // Position above dismount point
   %pos    = getWords(%obj.getTransform(), 0, 2);
   %oldPos = %pos;
   %vec[0] = " 0  0  1";
   %vec[1] = " 0  0  1";
   %vec[2] = " 0  0 -1";
   %vec[3] = " 1  0  0";
   %vec[4] = "-1  0  0";
   %impulseVec  = "10 0 0";
   %vec[0] = MatrixMulVector( %obj.getTransform(), %vec[0]);

   // Make sure the point is valid
   %pos = "0 0 0";
   %numAttempts = 5;
   %success     = -1;
   for (%i = 0; %i < %numAttempts; %i++) {
      %pos = VectorAdd(%oldPos, VectorScale(%vec[%i], 3));
      if (%obj.checkDismountPoint(%oldPos, %pos)) {
         %success = %i;
         %impulseVec = %vec[%i];
         break;
      }
   }
   if (%forced && %success == -1)
      %pos = %oldPos;

   %obj.mountVehicle = false;
   %obj.schedule(4000, "mountVehicles", true);

   // Position above dismount point
   %obj.setTransform(%pos);
   %obj.applyImpulse(%pos, VectorScale(%impulseVec, %obj.getDataBlock().mass));

   %obj.unmount();
   %obj.setControlObject(%obj);
   %obj.vehicleTurret = "";
}

function Armor::onCollision(%this,%obj,%col)
{
   if (%obj.getState() $= "Dead")
      return;

   // Try and pickup all items
   if (%col.getClassName() $= "Item") {
      %obj.pickup(%col);
      return;
   }

   // Mount vehicles
   else
   {
      %this = %col.getDataBlock();
      if ((%this.className $= WheeledVehicleData) && %obj.mountVehicle &&
           %obj.getState() $= "Move" && %col.mountable)
      {
         // Only mount drivers for now.
         %node = 0;
         %col.mountObject(%obj,%node);
         %obj.mVehicle = %col;
      }
   }
}

That will enable you to mount vehicles upon collision with them. When you press space, you will dismount. No need to add anything new to default.bind.cs.

A better solution would be to use the Torque Vehicle Resource.
#7
10/01/2006 (9:00 am)
Try this Tim but it crash the engine. I am checking to see what goes on. It dawn me this morning that I try to help him with my code that I hack for the horse. The spacebar jump is use for when player mount the horse, when pressing the spacebar the player and horse move as one. For horse jumping over things with the player. ctrl x is use to dismount the horse.
#8
10/01/2006 (9:51 am)
Hi Michael, it shouldn't crash. I tested on a fresh install. Maybe you have some other code that is conflicting with this?
#9
10/01/2006 (11:40 am)
That what I am think I have never had problem with any of your code. I still looking into it. Thanks.
#10
10/01/2006 (11:52 am)
I would still recommend taking a look at the vehicle resource if you haven't already done so. I use that as a base for my vehicle code and it works like a charm.
#11
10/01/2006 (1:37 pm)
This is great - I'll try this tonight.
#12
10/02/2006 (4:58 am)
Does anyone have a tutorial that works and explains whats going on for vehicles?

And by works I mean you do it one time and don't have to add anything else to get it working. All these non-working tutorials are driving me crazy.
#13
10/02/2006 (6:25 am)
The Torque Vehicle Resource works just fine.
#14
10/02/2006 (8:13 am)
I'll try it again but reading through the comments on that page it had mistakes, and it wouldnt work when i 1st tried it. console said 'mountvehicle' is not a valid server command or something.

i had another version working before doing that one so it's not a big deal.