Mount enemy to vehicle
by Andy Hawkins · in Torque Game Engine Advanced · 06/15/2007 (5:56 pm) · 2 replies
To get my bot to fly around using setMoveDestination, I'm doing this...
1. Create a vehicle
2. Create a Player
3. Mount the player to the vehicle.
But I'm getting these errors..
I think the code that causes it, isn't the right context for a bot.
... but I don't know. I think this is wrong because %client.player is me right? Not the bot.
Here's my code to do all this. Basically the bot wont mount the vehicle. Any help would be appreciated.
In command.cs...
in Ai_control.cs...
1. Create a vehicle
2. Create a Player
3. Mount the player to the vehicle.
But I'm getting these errors..
Quote:BRAVE/server/scripts/commands.cs (58): Unable to find object: '' attempting to call function 'getEyePoint'
BRAVE/server/scripts/commands.cs (61): Unable to find object: '' attempting to call function 'getEyeVector'
I think the code that causes it, isn't the right context for a bot.
%pos = %client.player.getEyePoint(); // Start with the shape's eye vector... %eye = %client.player.getEyeVector();
... but I don't know. I think this is wrong because %client.player is me right? Not the bot.
Here's my code to do all this. Basically the bot wont mount the vehicle. Any help would be appreciated.
In command.cs...
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");
}
}in Ai_control.cs...
datablock PlayerData(HumanAIPlayer : HumanMaleCivillian1)
{
shootingDelay = 100;
};datablock AIPlayer::LoadEntities()
{
// %targetObject is spawn point
%localname = "Harvester";
%enemyVehicle = AIPlayer::spawnVehicle(%localname,%targetObject);
// now create a pilot
%player = AIPlayer::spawnAtMarker("Human Male" @ %id, %targetobject, %id);
// then mount it...
AIPlayer::MountVehicle(%player, %enemyVehicle);
}function AIPlayer::MountVehicle(%obj, %targetObject)
{
echo("Found a vehicle: " @ %targetObject);
serverCmdMountVehicle(%targetObject.getDataBlock(),%obj,%targetObject);
}function AIPlayer::spawnAtMarker(%name,%obj,%id)
{
// Spawn a player and place him on the first node of the path
if (!isObject(%obj))
return;
%player = AIPlayer::spawn(%name, %obj,%id);
return %player;
}function AIPlayer::spawn(%name, %obj, %id)
{
// Create the demo player object
%player = new AIPlayer() {
dataBlock = HumanAIPlayer;
isbot=true;
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
return %player;
}function AIPlayer::spawnVehicle(%name,%spawnPoint)
{
// Create the player object
%vehicle = new FlyingVehicle() {
dataBlock = Drone;
};
MissionCleanup.add(%vehicle);
// Player setup...
%vehicle.setTransform(%spawnPoint.getTransform());
%vehicle.setShapeName(%name);
return %vehicle;
}
#2
The error
in my vehicle class file...
I hope this helps other people :)
06/16/2007 (7:34 am)
Also a crucial part - which I have no idea how old the info is... is to change the vehicle, so the weapons can still be mounted after the player is mounted...The error
Quote:...comes up if you don't do this...
Unknown command setObjectActiveImage.
in my vehicle class file...
function FlyingVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
if ($add_Missiles == true && $stop_adding == false)
{
echo("mounting launchers");
%obj.mountImage( RocketLauncherImage, 0 );
%obj.setImageAmmo( 1, 1 ); // **** CHANGED THIS.... used to be ( 0, 1 ) - 0 is for the seat
// this is an override in plasmaLauncher.cs and should really be set via a parameter
%obj.mountImage( RocketLauncherImage2, 1 );
%obj.setImageAmmo( 2, 1 ); // ***** CHANGED THIS.....used to be ( 1, 1 ) - slide up the slot numbers
%obj.nextWeaponFire = 1;
$add_missiles = false;
$stop_adding = true;
}
}I hope this helps other people :)
Associate Andy Hawkins
DrewFX
I needed to include "vehicle.cs" from the racing demo, to get the function onMountVehicle(%targetObject.getDataBlock(),%obj,%targetObject); to work.
I changed my initialisation code to look like this (the mountable setting was missing as well...)
in AI_Control.cs (in AIPlayer::LoadEntities()...
... %enemyVehicle = AIPlayer::spawnVehicle(%localname,%targetObject); %enemyVehicle.mountable = true; %enemyVehicle.setEnergyLevel(60); ... // now create a pilot %player = AIPlayer::spawnAtMarker("Human Male" @ %id, %targetobject, %id); // then mount it... AIPlayer::MountVehicle(%player, %enemyVehicle); ...So I changed the function in AI_Control.cs to look like this...function AIPlayer::MountVehicle(%obj, %targetObject) { echo("Found a vehicle: " @ %targetObject); onMountVehicle(%targetObject.getDataBlock(), %obj, %targetObject); }added the vehicle.cs function to the project and loaded it in game.cs with...
in game.cs...
... exec("./staticShape.cs"); exec("./radiusDamage.cs"); exec("./vehicle.cs"); // added this line ...and the vehicle.cs looks like this with the onMountVehicle function...
// ******************************************* function onMountVehicle(%vehicle, %obj, %col) { // Is the vehicle currently mountable? if (%col.mountable == false) { echo("Sorry, the vehicle is not mountable."); return; } // Check the speed of the vehicle. If it's moving, we can't mount it. // Note there is a threshold that determines if the vehicle is moving. %vel = %col.getVelocity(); %speed = vectorLen(%vel); if ( %speed <= %vehicle.maxMountSpeed ) { // Find an empty seat %seat = findEmptySeat(%col, %vehicle); %obj.mVehicle = %col; %obj.mSeat = %seat; %obj.isMounted = true; echo("Mounting vehicle in seat " @ %seat); // Now mount the vehicle. %col.mountObject(%obj,%seat); } else { echo("You cannot mount a moving vehicle."); } }// This function locates the next free seat in // the vehicle. // ******************************************* function findEmptySeat(%vehicle, %vehicleblock) { echo("This vehicle has " @ %vehicleblock.numMountPoints @ " mount points."); for (%i = 0; %i < %vehicleblock.numMountPoints; %i++) { %node = %vehicle.getMountNodeObject(%i); if (%node == 0) { return %i; } } return -1; }