Game Development Community

need help with setting up mount vehicles on keypress

by deepscratch · in Torque 3D Professional · 12/17/2010 (11:21 am) · 8 replies

hi there,
I've been struggling with this for too long now,
anyone can help me set up mounting vehicles by keypress only??

I need to use vehicles for cover, there are lots of vehicles close together, and the player keeps mounting them when close, so I need to be able to mount only when I want, by keypress.

please can you help?

thanks

#1
12/17/2010 (1:12 pm)
Wasn't there a resource that does this ? Think it was for TGEA but it's probably a good place to start:

www.torquepowered.com/community/resources/view/11831
#2
12/17/2010 (1:56 pm)
thanks Richard, had issues with that one, but there is a link to a more promising option
#3
12/17/2010 (8:00 pm)
The old FPS scripts did have that functionality... if you still have a copy of the early pre-release betas. Some of the 'helper' functions are still around and if I recall correctly you really only need a keybind to call a raycast check and do "something" if it hits a vehicle (or other things), other than that it's a simple easy change to prevent the onCollision type mounting once you have your raycast working.
#4
12/18/2010 (1:38 am)
nope, still no luck, the raycast sees nothing, not even sure its working, no echo returns, nothing, and I still just mount on collision.

dunno what I'm doing wrong.

I believe this to be the correct function:
// ----------------------------------------------------------------------------
// Vehicle mounting from a keypress
// ----------------------------------------------------------------------------
function serverCmdMountVehicle(%client)
{
   %player = %client.player;
   if(!isObject(%player) || %player.getState() $= "Dead" || !$Game::Running)
      return;

   // TODO:  Can (will probably) add seat switching right here.

   %range = 20;
   %mask = $TypeMasks::VehicleObjectType;
   %searchResult = %player.doRaycast(%range, %mask);

   if (%searchResult && %player.mountVehicle)
   {
      %vehicle = firstWord(%searchResult);
      if (!%vehicle.mountable)
      {
         messageClient(%client, 'MsgMountFailed', 'c2Vehicle is not useable.');
         return;
      }

      %vel = vectorDot(%vel, vectorNormalize(%vehicle.getVelocity()));
      if (%vel <= %vehicle.getDataBlock().maxMountSpeed)
      {
         messageClient(%client, 'MsgMountSuccess', 'c2Entering %1.', %vehicle.getDataBlock().nameTag);
         %player.mountVehicles(false);
         %vehicle.getDataBlock().mountPlayer(%vehicle, %player);
         return;
      }
      else
      {
         messageClient(%client, 'MsgMountFailed', 'c2Cannot enter a moving vehicle.');
         return;
      }
   }
   else
   {
      messageClient(%client, 'MsgMountFailed', 'c2No vehicle in range.');
      return;
   }
}
#5
12/18/2010 (1:41 am)

I also tried this for the raycast:

//-----------------------------------------------------------------------------------------------------------------
// Use Button - will popup menus on objects - for mounting vehicles, accessing 
// gui interfaces, etc...
// Casts a Ray and determines what object it is and what menu to push. 
//-----------------------------------------------------------------------------------------------------------------

function serverCmdUseButton(%client, %arg)
{
   // scope the player
   %player = %client.getControlObject();
   
   // key is being pressed	
   if(%arg)
   {   
      if(!%client)   
      {      
   	   return;
      } 
   
      if(%player.isMounted == 1)   
      {      
   	   return;
      }
      
      // RAY_CASTING
	   
	   //echo("%client: " @ %client);
	   //echo("%arg: " @ %arg);
	   //echo("%player: " @ %player);
	      
	   // muzVec is the vector coming from the gun's "muzzle"
      %muzVec = %player.getMuzzleVector(%slot);

      // muzNVec = normalized muzVec
      %muzNVec = VectorNormalize(%muzVec);

      // range of ray
      %range = 50;

      // scale muzNVec to the range the beam can reach
      %muzScaled = VectorScale(%muzNVec, %range);

      // muzPoint = the actual point of the gun's "muzzle"
      %muzPoint = %player.getMuzzlePoint(%slot);

      // rangeEnd = muzzle point + length of beam
      %rangeEnd = VectorAdd(%muzPoint, %muzScaled);
	
      %searchMasks = $TypeMasks::StaticObjectType |               
                     $TypeMasks::StaticShapeObjectType |
                     $TypeMasks::CorpseObjectType |
                     $TypeMasks::ItemObjectType |
                     $TypeMasks::VehicleBlockerObjectType |
                     $TypeMasks::VehicleObjectType |
                     $TypeMasks::WaterObjectType;

      
      // search for objects within the beam's range that fit the masks above
      %scanTarg = ContainerRayCast(%muzPoint, %rangeEnd, %searchMasks, %obj);

      if(%scanTarg)
      {
         %serverID = getWord(%scanTarg,0);
         		
		   // echo("%scanTarg.getClassname(): " @  %scanTarg.getClassname());
	
         switch$(%scanTarg.getClassname())
         {		
	case StaticShape:
	echo("Player is targeting  a StaticShape - Server ID = " @ %serverID);
	// Do stuff
                 		      
            case Player:
            echo("Player is targeting another player - Server ID = " @ %serverID);            
            // Do stuff

            case WheeledVehicle:
            
                   %serverID.mountObject(%player, 0);
                   %player.isMounted = 1;
			
            case FlyingVehicle:
            //echo("Player is targeting a vehicle - Server ID = " @ %serverID);
            // Do stuff

            case HoverVehicle:
            //echo("Player is targeting a vehicle - Server ID = " @ %serverID);
            // Do stuff

            case InteriorInstance:
            //echo("Player is targeting a building - Server ID = " @ %serverID);
            // Do stuff

            case TerrainBlock:
            //echo("Player is targeting the ground - Server ID = " @ %serverID);
            // Do stuff

            default:
            // Do stuff
         }
      }
   }
   
   // key is being released
   else
   {
	// Do Stuff
   }	 		
}

what am I missing here?
#6
12/18/2010 (7:08 am)
Possibly a silly question, but did you delete prefs when you added the new keybind?
#7
12/18/2010 (12:32 pm)
Is this simply not an issue of calling the actual mount function on a keypress instead of OnCollision?

If you do a check for mountable vehicles within say... 2 or 3 units of the player position then mount.
#8
12/18/2010 (2:33 pm)
Bloodknight for the win!!!

perfect man, works a treat now ;o)