Game Development Community

When items collide with other items

by Alex Scarborough · in Torque Game Engine · 01/18/2005 (11:26 pm) · 5 replies

Long story, but I found need to make item objects collide with each other. The solution I decided on (which is probably incorrect after what I've gone through) was to add ItemObjectType to sClientCollisionMask. Upon a clean recompile, I loaded up Torque with trace on. Strangely, and much to my horror, Torque crashed within seconds. Looking over console.log, I noticed something incredibly odd: The items were calling collisions against themselves! Console.log was filled with "entering Healthpatch::onCollision(16, 1734, 1734)" Right, so add %obj.setCollisionTimeout(%obj) to Healthpatch::onAdd. Again, a crash, same story. I went back to item.cc, and I guess I was sleep deprived, because I removed the following lines:

if(mCollisionObject)
	     mCollisionObject->disableCollision();
and
if(mCollisionObject)
	     mCollisionObject->enableCollision();
from Item::updateWorkingCollisionSet(). For whatever reason, this stopped the collisions and the crashes.

Fast forward three days. I'm still working on the issue that required colliding items. I encounter a new problem (now using a custom Rock item). Whenver a Rock item's z position was between 254.25 and 256.25, it would repeatedly call collisions against itself. I went back to item.cc, noticed that some lines had been removed from updateWorkingCollisionSet() and put them back in. The original error did not return, but the new one remains.

As near as I can tell, this is an error somewhere in the source code. The item calling updateWorkingList has had collisions disabled so it shouldn't be able to call collisions against itself. But... it does.

I see four possible solutions:
1) There is a different way to make items collide against each other and I never should have added ItemObjectType to the collision mask in the first place
2) I'm missing some piece to the puzzle and only made some of the necessary changes.
3) There is a bug somewhere in the source code, presumably at a low level.
4) Occam's Razor: If the item only calls collisiosn against itself at those z values, lower the terrain so it can't reach those z values.

Still, this whole situation leaves me incredibly confused, and somewhat sleepless. Especially how the source code change fixed the first glitch where items would continuously call collisions against themselves, but putting it back in didn't also recreate that peculiar glitch. Also at one point where I had both rocks and health patches in the same map, the health patches would have issues but not the rocks. Another thing that came up is sometimes Torque would alternate between crashing and booting me from the server (single player game) because of a bad packet update.

On the plus side, I've learned that if you're gonna go in over your head, you may as well try to do it with style.

#1
01/19/2005 (4:11 pm)
Right, now that I'm out of a sleep deprived stupor...

Rock1 derives from the Item class. It's onCollision function is just some echo commands sending back the transform of %obj, the transform of %col, and if %obj == %col, it echoes back "Colliding with self... what?!?!?!"

Here's a sample of what is in console.log:

Entering Rock1::onCollision(21, 1434, 1434, 0.000000 0.000000 0.000000, 0.000000)
   385.043 166.931 254.781 1 0 0 0
   385.043 166.931 254.781 1 0 0 0
   Colliding with self... what?!?!?!
Leaving Rock1::onCollision() - return 
Entering Rock1::onCollision(21, 1434, 1434, 0.000000 0.000000 0.000000, 0.000000)
   385.043 166.931 254.781 1 0 0 0
   385.043 166.931 254.781 1 0 0 0
   Colliding with self... what?!?!?!
Leaving Rock1::onCollision() - return


and it continues like this until

Entering Rock1::onCollision(21, 1434, 1434, 0.000000 0.000000 0.000000, 0.000000)
   385.043 166.931 254.266 1 0 0 0
   385.043 166.931 254.266 1 0 0 0
   Colliding with self... what?!?!?!
Leaving Rock1::onCollision() - return 
Entering Rock1::onCollision(21, 1434, 1434, 0.000000 0.000000 0.000000, 0.000000)
   385.043 166.931 254.266 1 0 0 0
   385.043 166.931 254.266 1 0 0 0
   Colliding with self... what?!?!?!
Leaving Rock1::onCollision() - return

I am completely lost. Objects shouldn't be able to add themselves to their working collision list. And it only has this issue around those Z coordinates.
#2
01/19/2005 (4:51 pm)
After messing around with it a bit more, I noticed something. It isn't just from 256 to 254 or so. It's at *every* z value that is a power of 2, give or take about 5. So, if there's a reason to the madness, there must be some sort of solution in there somewhere...
#3
03/25/2005 (7:59 pm)
Hi Alex,
did you ever fix this problem? I had a problem with the items "floating" when I added the ItemObjectType to the collision mask. Like they ignored gravity. The collided with other objects ok (I also didn't have any crashes?) but when they moved off ledges, the wouldn't fall.

Harley.
#4
03/28/2005 (7:28 am)
Add disableCollision(); to Item::updatePos as the first line. That should do it.
#5
11/10/2011 (8:53 am)
Came across this while porting http://www.garagegames.com/community/resources/view/3937/ to T3D 1.1 Final.
All is working except sometimes they "float".
disableCollision(); didn't remedy it.
Still looking for a solution.