Game Development Community

ShapeBaseData::onCollision callback issue - NOT A BUG

by Lunacy · in Torque 3D Professional · 05/17/2011 (9:41 am) · 6 replies

Hello,

So this is not really a bug thread, but still something annoying.
It seems that the onCollision callback is not systematically called when an object collides with another.

To replicate the issue, create a StaticShapeData (Rock1), using the stock "rock1.dts" object as the shape. Then add this callback somewhere:

function Rock1::onCollision(%this, %obj, %collObj){
   %collObj.applyImpulse(%collObj.getPosition(), "0 0 1000");
}

rock1.dts already has a collision mesh, so it should work. Place the rock somewhere, and jump on it. After a few jumps, the player will stop, sometimes after just 1 bounce. Same results with different types of collision meshes.

I have been advised to use a Trigger, or a physical zone, to achieve what I want to do (bouncing platforms/objects), or even a proper physics engine, but I still find it annoying that the onCollision callback isn't reliable enough.

So is there anything I can do to "fix" this behaviour, and get my bouncing platform working?
Thanks for help.

This may, or may not, be related to this issue, I have no idea.

#1
05/17/2011 (11:15 am)
Try to change the timeout (CollisionTimeoutValue) in shapeBase.
#2
05/17/2011 (12:11 pm)
That was something I was thinking of, without looking too much for it in the code. I've tried several different values (both smaller and larger than the original value) and rebuilt, but haven't noticed any change.. Thanks anyway
#3
05/17/2011 (1:02 pm)
I think this is not a bug,because there is a method queueCollision() that should weed old collisions for the same period of time.This is used to prevent from calling onCollision multiple times per period,etc..
I think you hit the early out at the beginning of this code.

I would implement the bouncing player in a different way.
You apply an impulse on the server, it means you get a correction write packet for every impulse.This is slow.
I would use _findContact() to get the collision and apply the impulse in the player class.This way you bypass the weeding and the correction packet.
#4
05/17/2011 (1:42 pm)
Ok so I'm not exactly sure about how queueCollision() works, but it only gets called when the player actually bounces; meaning, if the player fails to bounce when it should, queueCollision() isn't even called.

Thanks for suggesting another way to implement it, however I don't feel like adding new stuff to the source code already; I don't feel confident enough at the moment, and I feel like it's going to be a waste of time for me, especially since I get it working "fine" with triggers located on top of objects. But it still does not answer the question of missed collisions.
#5
05/18/2011 (11:26 am)
Bump, in case someone wants to share his experience, or suggest a way to fix/deal with it.
#6
05/19/2011 (1:12 pm)
Well, I guess it's going to stay as it is, for the moment... I'll use triggers. A bit surprising that I'm the only one bothered with this problem. Thanks anyway.


EDIT: DEDEN suggested this fix, which does not seem to break other stuff at the moment :

in player.cpp, around line 3660 ( in Player::_handleCollision), comment out
&& collision.object != mContactInfo.contactObject"

Not sure why it's there, but removing it solves the problem for me.