Game Development Community

Mount/dismount a vehicle

by Dan Keller · in Torque Game Engine · 12/24/2005 (5:47 pm) · 1 replies

I'm having yet *another* problem with flying vehicles. When I mount it, I can fly it just fine, but when I dismount it, it continues to be controlled by the keyboard and mouse. The onCollision and doDismount functions for my player look like:
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;

   //dismount anywhere

   %obj.mountVehicle = false;
   %obj.schedule(4000, "mountVehicle", true);
   %obj.unmount();
   %obj.mVehicle = "";
}


//----------------------------------------------------------------------------

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

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

   // Mount vehicles
   %this = %col.getDataBlock();
   if ((%this.category $= "Vehicles") && %obj.mountVehicle && %obj.getState() $= "Move"){

      // Only mount drivers for now.
      %node = 0;
      %col.mountObject(%obj,%node);
      %obj.mVehicle = %col;
   }
}

#1
12/24/2005 (7:28 pm)
Ahhh A common issue. Heres the code for mine. Where %obj is is the player object number.

function onPlayerDismount(%vehicle, %obj, %col)
{
	%obj.unmount();
	%obj.setControlObject(%obj);
	%obj.mounted = "0";
	%obj.isMounted = false;
	onPlayerUnMount();
}


Theres 1 command to mount, and 2 commands to dismount, if you don't call SetControlObject, you'll have this problem.