Game Development Community

Bug in player:findContact?

by Steve Lamperti · in Torque Game Engine · 04/25/2007 (10:19 am) · 1 replies

The following code in the FindContact method of Player seems to me to be doing nothing, unless I am missing something; (starting on about line 2770 in 1.5.1.)

Box3F plistBox = wBox;

   // Expand build box as it will be used to collide with items.
   // PickupRadius will be at least the size of the box.
   F32 pd = mDataBlock->pickupDelta;
   wBox.min.x -= pd; wBox.min.y -= pd;
   wBox.max.x += pd; wBox.max.y += pd;
   wBox.max.z = pos.z + mScaledBox.max.z;

What looks wrong to me is that pListBox is set to wBox before wBox is modified, and later in the code, pListBox is referenced, not wBox, so I don't see this code as doing anything. A simple fix, if this is correct, would be to move the Assignment of plistBox after the rest of the code.

#1
04/25/2007 (10:12 pm)
WBox is a local variable and is not used again in that method so it seems the above manipulation of wBox is pointless, unless...

reffering to the following comment

// Expand build box as it will be used to collide with items.
// PickupRadius will be at least the size of the box.


it would suggest that the real bug is further down in that method where it checks for collision with item class objects
else if (objectMask & ItemObjectType)
      {
         // If we've overlapped the worldbounding boxes, then that's it...
         Item* item = static_cast<Item*>(pConvex->getObject());
         if ([b]getWorldBox()[/b].isOverlapped(item->getWorldBox()))
            if (this != item->getCollisionObject())
               queueCollision(item,getVelocity() - item->getVelocity());
      }

The code is using the worldbox (bounds box in world coordinates) to determine if it should pickup an item, but it clearly is supposed to use a box which includes the pickup radius so that items can be picked up from a slightly greater distance.

Swap the bold getWorldBox() in the above code with wBox and it begins to make sense as to what the developer had in mind.