Game Development Community

Triggers for Pathshape

by Richard Sopuch · in Torque Game Engine · 04/21/2005 (4:07 am) · 4 replies

Hi everyone,

I am beginner in Torque and I hope someone will help me.

In my game I use the pathshape as a player. I set the trigger, but the onEnterTrigger functions are not being called. It seems I missed something. Does trigger react for pathshape object? What should I add to the trigger or to the pathshape? onCollision, onTrigger functions? Or something else?

Any answer will be appreciate.

Richard

#1
04/21/2005 (4:14 am)
Does your shape have a collision mesh? Without one it wont trigger the onEnterTrigger...
#2
04/21/2005 (6:57 am)
I think yes, but I'm not sure if it is correct collision mesh (I'm beginner in modeling too). I created the model in MilkShape.
Is it enough create the collision mesh by choosing the Bounding box option in Milkshape -> Torque exporter? This I did.
How can I check if collision mesh is correct?
#3
09/23/2008 (9:03 am)
I know this is a very old thread but I found it so others will.

I'm working on the trigger problem at the moment, I've discovered that in the vehicle class there is a function checkTriggers called every update. This uses a ShapeBaseConvex to check if the vehicle has entered a trigger or item. So I'm now working on transferring this over to pathShape.

I'll let people know how I get on

PS
I'm using TGEA 1.7.1
#4
09/23/2008 (9:15 am)
Sweet it worked

So in PathShape. h you need to add

ShapeBaseConvex mConvex;

and in the ShapeBaseConvex you need to make PathShape a friend of ShapeBaseConvex

friend class PathShape;

Now in onAdd for PathShape add the following

mConvex.mObject    = this;
   mConvex.pShapeBase = this;
   mConvex.hullId     = 0;
   mConvex.box        = mObjBox;
   mConvex.box.min.convolve(mObjScale);
   mConvex.box.max.convolve(mObjScale);
   mConvex.findNodeTransform();

and then add these functions

void PathShape::checkTriggers()
{
   Box3F bbox = mConvex.getBoundingBox(getTransform(), getScale());
   gServerContainer.findObjects(bbox,sTriggerMask,findCallback,this);
}


void PathShape::findCallback(SceneObject* obj,void *key)
{
   PathShape* vehicle = reinterpret_cast<PathShape*>(key);
   U32 objectMask = obj->getTypeMask();

   // Check: triggers, corpses and items, basically the same things
   // that the player class checks for
   if (objectMask & TriggerObjectType) {
      Trigger* pTrigger = static_cast<Trigger*>(obj);
      pTrigger->potentialEnterObject(vehicle);
   }
}

sTriggerMask is a static a stole from Vehicle.cpp and changed abit, stick it at the top of PathShape.cpp

static U32 sTriggerMask = ItemObjectType     |
                          TriggerObjectType;

Now in processTick you just need to update the mConvex with the path transform and Call check trickers like so

mConvex.transform = &mat;
   //check if the shape entered any triggers
   checkTriggers();

It worked for me.

Hope this helps others, this is my first post, but am loving the community for torque (made learning so much easier) so thought I should help out too.

Cheers
Tom