Game Development Community

Mounting Woes. Can anyone help?

by Devon Ly · in Torque Game Engine · 03/28/2004 (4:30 am) · 7 replies

I'm trying to mount a turret onto my tank, and the code seems right and everything seems to tell me that the turret does indeed get mounted.
I'm just wondering if I have to do anything else for it to show up on the screen.

I'm assuming the following steps are required
1. create the turret datablock
2. create the tank datablock
3. create an onAdd method for the tank
3a. To that method dynamically create a turrent object and mount it onto the tank.

That should be it right? The engine then handles the rendering and so forth from there.
Let me know if i'm wrong.


function HeavyHoverTank::onAdd(%this,%obj)
{
echo(">>>>>>>>>>>>>ATTEMPTING TO MOUNT TURRET<<<<<<<<<<<<<<<");

%turret = new Item(){
dataBlock = HeavyTurret;
};

// Manually add a mount point to the TANK'S mount list
// If your reading this I hacked up setMountPoint so I could manually
// add mount nodes that were not loaded by the engine as default.
%obj.setMountPoint("turretmount");

// Mount the turret onto our tank
%obj.mountObject(%turret,0);
// %obj.mountedTurret = %turret;
if (%turret.isMounted())
{
echo("THIS TURRET HAS BEEN SUCCESSFULLY MOUNTED");
}
}

Thanks

#1
03/28/2004 (4:55 am)
Quote:
%obj.setMountPoint("turretmount");

// Mount the turret onto our tank
%obj.mountObject(%turret,0);

Shouldn't
%obj.mountObject(%turret,0);
be
%obj.mountObject(%turret,"turretmount");
?
#2
03/28/2004 (5:20 am)
Nah the code was right chris, the mounting points are actually stored as indexes. which is why it needs to be 0 but yeah some kind of string or hash table would of been nice.

but it still doesn't explain why I can't see my turret on screen. Very frustrating. I can't seem to find any documentation that describes any of this.
#3
03/28/2004 (11:36 pm)
*bump*
#4
03/29/2004 (12:13 am)
Devon, it would help if you posted your "hacked" code also, since I think TGE usually expects mountpoints to be named "mount0" ... "mountn", so when you call %obj.mountObject(%turret,0); the engine searches for a "mount0" node... but I guess you have changed that, then, too...?
#5
03/29/2004 (1:52 am)
Stefan, yep it sure does. hang on let me get it off my "work" computer ;) i'll add it below
#6
03/29/2004 (2:00 am)
//////////////////////////////////////////
// Helper functions written by Devon Ly //
//////////////////////////////////////////
// This function allows a user to manually add a mounting point
// It searches through the mounting list and adds the point in the next available
// index position.

void ShapeBase::setMountPoint(const char* nodeName)
{

// Check to see if the loaded shape is legit *to lazy to do right now will add later

// If it is then check if the mount point list is full
// This assumes that Preload function has already attempted to search for mountX names and has set the nodes accordingly. This check will not work if you run it before preload.
*note to self: check constructor and ensure mountPointNode array has all elements wiped to -1
if (mDataBlock->mountPointNode[ShapeBaseData::NumMountPoints] != -1)
{
// Display a message that the list is full
Con::warnf("Warning: The mount point list is full, cannot add any further points");
}
else
{

// if it isn't then search for the desired point and add it

// find the first available slot
int z = 0;
while ( mDataBlock->mountPointNode[z] != -1 )
{
z++;
}

mDataBlock->mountPointNode[z] = mDataBlock->shape->findNode(nodeName);

if (mDataBlock->mountPointNode[z] == -1)
{
// display an error message that the a node by that name does not exist
Con::warnf("Warning: The node %s does not exist in this shape", nodeName);
}

}
}
#7
03/29/2004 (4:07 am)
Try this:

// Datablock
datablock StaticShapeData(HeavyTurret)
{

shapeFile = "RM/data/shapes/turret/turret.dts"; // change to match turret shape

};

// Mounting
%turret= new StaticShape() {
dataBlock = HeavyTurret;
};
%obj.setMountPoint("turretmount");
%obj.mountObject(%turret, 0);