Game Development Community

Bug in First Collision Detection of Two Object?

by Charlie Patterson · in Torque Game Builder · 05/19/2011 (4:55 pm) · 5 replies

If I have a moving object collide with a stationery object, I get an onCollision. However, if I stop the moving body as part of the collision callback, I do not receive any follow up callbacks. It seems to me that if I stop it after they are considered touching, they should still be touching. No?

As some pseudo-code:

// somewhere in code we'll have an object movingObject of class Moving
%movingObject.setLinearVelocityX(2);

// now our collision callback for the movingObject
// note this will only get called once surprisingly!?
function Moving::onCollision(...)
{
   ...

   // stop now that we're touching the enemy
   %this.setLinearVelocityX(0);

   ...
}

#1
05/21/2011 (3:15 am)
I would of expected that as default behavior as the function Moving::onCollision will only be called when they first collide.
If they then continue to collide it won't call again until they have first stopped colliding otherwise the collision stack wouldn't get to do any other collisions.
Thats how I understand it.
I think this post about triggers and collisions explains it best.

www.garagegames.com/community/forums/viewthread/87407

BTW: The trigger problem in that post still exists and hasn't been fixed yet. :(
#2
05/21/2011 (10:38 am)
Thanks peterjohn!

I read the article you point to but I think I have a different concern, because I have no triggers. Once my two objects are "good and overlapping" I get collision callbacks every frame. To force them to be certainly overlapping, I've been letting the moving object continue forward 75ms before stopping it (by using a scheduled callback of my own once they first collide). However, hacks like this lead to long-term complications I'm trying to avoid. For instance, a faster object may go way too far in 75ms.

If I had to guess, when two objects first touch, perhaps the physics engine moves them off of each other due to the CLAMP or STICKY setting?! I tried both and I still have the current problem. (Note though, that I currently have all receive/send physics turned off). If I'm onto something here, perhaps I'd need a "collision response" of "NONE"'. Then I would just get a callback.

I'm the only one with this?

#3
05/21/2011 (8:36 pm)
Would not of expected that, but in that case, can't you just move one of the object when they first collide to make sure they both are good and overlapping from first impact instead of waiting 75ms?.
#4
05/22/2011 (5:03 pm)
Yeah, I tested adjusting the position of the moving object, instead of waiting to stop it. In either case, I don't feel the solution is general. For instance, by moving things 0.1 world coordinates, in some (rare) cases that may be too far.
#5
05/23/2011 (12:36 am)
The offset engine applies to keep objects separate must be really small, 0.001 ... 0.0001 maybe.

One other solution I can see is to remember that object has been stopped - it will remain in that state until your code set it in motion again, or collision to the other object occur, then you can reset your isStopped variable.