Avoid duplicitous collisions?
by Jason McIntosh · in Torque Game Builder · 07/22/2005 (9:29 pm) · 6 replies
Is there a way to enforce colliding only once with the same object per sceneTime tick? I want to avoid multiple onCollision calls with the same object.
About the author
#2
07/23/2005 (8:49 am)
Hey, that seems to have worked pretty well (after a brief test). I just hope that it still works under bad framerate conditions since the schedule() isn't based on scenegraph time. Thanks for the suggestion, Philip! :)
#3
07/23/2005 (1:42 pm)
Increment a counter for each collision that refreshes per sceneTime tick, and check it with an if statement to make sure that value isn't greater than 0?
#4
Turning off collisions and then scheduling them back on works ok, but there are some cases where the objects slide through each other somwhat, so I don't use it for everything.
07/23/2005 (1:50 pm)
That's a good idea, too. I was saving the "last collided object" and the "last collision scene time" and comparing them on each collision, but it didn't seem to work. *shrugs*Turning off collisions and then scheduling them back on works ok, but there are some cases where the objects slide through each other somwhat, so I don't use it for everything.
#5
07/24/2005 (4:39 am)
Matt, Nice idea. I have some code that uses schedules and I was concerned about the lack of synchronisation between schedule timings and scene updates. Thanks!
#6
Hopefully this will help some of you out - I am still learning so feel free to point out any troublesome parts with this method.
08/17/2005 (6:53 am)
I struggled with multiple collisions causing problems then found an easy away around this. I check the object's tag (which I set for all objects). Just set they colliding object's tag to null - then subsequent collisions will not meet the criteria - maybe my code will better explain://-----------------------------------------------------------------------------
// Name: fxSceneObject2D::onCollision(%srcObj, ...)
// Desc: Called when a collision is detected
//-----------------------------------------------------------------------------
function fxSceneObject2D::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
// Handle the source object
switch (%srcObj.tag)
{
// Player hit something
case "player":
if (%dstObj.tag $= "oilslick")
{
// Make sure you can't collide with dstObj more than once
%dstObj.tag = "";
echo("Collided with oilslick");
// Disable controls
playerMap.pop();
// Spin car sprite
$player.setAngularVelocity(360);
// Stop spinning car sprite in 4 seconds
schedule(4000,0,stopSpinning);
// Skidding Tires Audio.
alxPlay( skiddingTiresAudio );
}
if (%dstObj.tag $= "jump")
{
// Make sure you can't collide with dstObj more than once
%dstObj.tag = "";
echo("Collided with jump");
// Jump car sprite
playerJump();
}
}
}Hopefully this will help some of you out - I am still learning so feel free to point out any troublesome parts with this method.
Torque Owner Philip Mansfield
Default Studio Name