One Way Panel Physics
by Michael Smith · in Torque 2D Beginner · 06/17/2013 (11:29 pm) · 3 replies
I am working on a behavior for creating a one-way panel. That is, an object that allows certain objects to pass through in one direction only. I tried selectively turning off collisions for the object when it is touched from the "back" direction, like so:
This does not work. The box 2d contact which triggers the onCollision call is already made by the time this function is called so the collision is not suppressed. And in any case, this behavior is that of a door that opens when touched from behind rather than a platform that only supports things on top.
I could put a sensor under the platform and use it to trigger the platform to turn off the collision but it would still not have all the correct functionality.
The box 2d manual suggests disabling the individual contacts as they occur in the pre-solve event:
From the manual section 9.4:
Is there a way to do this or something like it in Torque script?
function oneWayPanelBehavior::onCollision( %this, %sceneObject, %collisionDetails )
{
%collisionNormal = %collisionDetails._2 SPC %collisionDetails._3; // Extract collision normal vector
%dotProduct = VectorDot( %this.solidDirection, %collisionNormal ); // Compare orientation of collision vector to direction of solidity
if( %dotProduct < 0 ) // If the collision was from the non-solid side then suppress collisions
{
%this.owner.setCollisionSuppress(true);
}
}
function oneWayPanelBehavior::onEndCollision( %this, %sceneObject, %collisionDetails )
{
%this.owner.setCollisionSuppress(false);
}This does not work. The box 2d contact which triggers the onCollision call is already made by the time this function is called so the collision is not suppressed. And in any case, this behavior is that of a door that opens when touched from behind rather than a platform that only supports things on top.
I could put a sensor under the platform and use it to trigger the platform to turn off the collision but it would still not have all the correct functionality.
The box 2d manual suggests disabling the individual contacts as they occur in the pre-solve event:
From the manual section 9.4:
Quote:Pre-Solve Event
This is called after collision detection, but before collision resolution. This gives you a chance to disable
the contact based on the current configuration. For example, you can implement a one-sided platform
using this callback and calling b2Contact::SetEnabled(false). The contact will be re-enabled each time
through collision processing, so you will need to disable the contact every time-step.
Is there a way to do this or something like it in Torque script?
About the author
Bible translator by day-- game programmer by night
#2
06/18/2013 (6:12 am)
If you get the Box2D SDK, you will find an example of one-way platforms. You an easily copy over the code, but Alien Cabbage is right. This need to be a C++ change. To get it to work in TorqueScript, you will want to apply a new field to the SceneObject class that declares it "one way." Let C++ handle the logic, while TorqueScript handles the flagging.
#3
06/18/2013 (12:01 pm)
That makes sense. I will post it as a feature request and see if anyone votes for it.
Alien Cabbage