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
About the author
Recent Threads
#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
but instead of onCollisssion().
i am using function WheeledVehicleData::onImpact().
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
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.
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.
Torque Owner Daniel Buckmaster
T3D Steering Committee