Cannot pick up objects
by Ken Davis · in Torque Game Engine · 10/21/2004 (4:37 pm) · 2 replies
I am new to Torque and I am trying modify the Emaga game from the 3DGPAI1. I have replaced the normal player with a hovertank. It is not a vehicle which the player has mounted, but rather the tank is the vehicle.
I think I have included all the necessary methods but the tank just runs thru the objects in the game and does not pick them up. Does anyone have any ideas? I am attaching the tank.cs file. Sorry if I did not attach it correctly.
-Ken
I think I have included all the necessary methods but the tank just runs thru the objects in the game and does not pick them up. Does anyone have any ideas? I am attaching the tank.cs file. Sorry if I did not attach it correctly.
-Ken
//-----------------------------------------------------------------------------
// And finally, this datablock describes the vehicle itself.
//-----------------------------------------------------------------------------
//**************************************************************
// VEHICLE CHARACTERISTICS
//**************************************************************
datablock HoverVehicleData(DefaultTank)
{
spawnOffset = "0 0 1";
floatingGravMag = 30; // 50.5
catagory = "Vehicles";
shapeFile = "~/data/models/avatars/human/Tank2.dts";
computeCRC = true;
Other tank stuff here.};
function DefaultTank::create( %block )
{
%obj = new HoverVehicle()
{
dataBlock = %block;
};
return( %obj );
}
//============================================================================
// Avatar Datablock methods
//============================================================================
function DefaultTank::onAdd(%this,%obj)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
%obj.mountVehicle = false;
// Default dynamic Avatar stats
%obj.setRechargeRate(0.01);
%obj.setRepairRate(%this.repairRate);
}
function DefaultTank::onRemove(%this, %obj)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
%client = %obj.client;
if (%client.player == %obj)
{
%client.player = 0;
}
}
function DefaultTank::onNewDataBlock(%this,%obj)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
}
function DefaulTank::onCollision(%this,%obj,%col,%vec,%speed)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
%obj_state = %obj.getState();
%col_className = %col.getClassName();
%col_dblock_className = %col.getDataBlock().className;
%colName = %col.getDataBlock().getName();
if ( %obj_state $= "Dead")
return;
if (%col_className $= "Item" || %col_className $= "Weapon" ) // Deal with all items
{
%obj.pickup(%col); // otherwise, pick the item up
}
// Mount vehicles
//%this = %col.getDataBlock();
%pushForce = %obj.getDataBlock().pushForce; // Try to push the object away
if (!%pushForce)
%pushForce = 20;
%eye = %obj.getEyeVector(); // Start with the shape's eye vector...
%vec = vectorScale(%eye, %pushForce);
%vec = vectorAdd(%vec,%obj.getVelocity()); // Add the shape's velocity
%pos = %col.getPosition(); // then push
%vec = getWords(%vec, 0, 1) @ " 0.0";
%col.applyImpulse(%pos,%vec);
}
#2
10/21/2004 (4:55 pm)
Thank makes sense. How would I implement that. Would it contain the logic I have in the onCollision function or does the onCollision function somehow call the pickup function?
Associate Anthony Rosenbaum
function DefaultTank::pickup(%this, %obj){ //pick up object }