Game Development Community

why the script function of WheeledVehicleData::onCollision is called twice sometimes ?

by Ji Xinyu · in Torque 3D Beginner · 09/29/2013 (7:55 pm) · 5 replies

I found that when the wheelevehicle collide with staticshape object,sometimes the function WheeledVehicleData::onCollision is called twice,but sometimes the function is called once.why?And when the function is called twice,when is called once?thanks

#1
09/29/2013 (8:36 pm)
I don't remember fully, but it's possible that the vehicle is actually colliding with the shape for two ticks. Are you able to reproduce the issue? I.e. does it only occur when you collide at a certain speed or angle?
#2
09/29/2013 (8:57 pm)
yes,I can reproduce the issue.It seems that when I drive the wheeledvehicle collide with the staticshape object at a heigh speed,the function wheeledvehicleData::onCollision() is called twice,and when I drive the vehicle collide with the staticshape object at a low speed the function is called once.the follows code is what I do.
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
   // Collision with other objects, including items
   echo("====WheeledVehicleData::collision is called=======");
}
And in the console.log,sometimes I can find the string "====WheeledVehicleData::collision is called=======" twice,sometimes once.
#3
09/29/2013 (9:00 pm)
the project i am working on have same problem.
but instead of onCollisssion().
i am using function WheeledVehicleData::onImpact().
#4
09/29/2013 (9:01 pm)
Vehicle collision works by letting the vehicle overlap other objects, then detecting this and applying forces to separate the two objects. I suspect that at high speeds, the vehicle penetrates far enough into the object that it doesn't fully separate in the next tick, so the collision happens again.
#5
09/29/2013 (9:16 pm)
You can try keeping the simID of objects you have collided with for a short time then test to see if you've collided with them two ticks in a row. Then discard the second collision.

Probably should look at how it's triggered on the engine side and see if there's a way to prevent re-triggering "ongoing" collision callbacks. Perhaps use a similar mechanism to a trigger - on entering the collision fire the callback and ignore the object until it has exited the first collision before triggering another.