Using triggers
by Alejandro Lopez · in Torque Game Engine · 05/12/2008 (9:07 am) · 7 replies
Any body can give a example of how to detect when a ball ( item ) enter to a zone using a trigger.
thnks
thnks
#2
edit:spelling
05/12/2008 (10:13 am)
function triggerSapo::onEnterTrigger( %this, %trigger, %obj )
{
if ( %obj.getType() & TypeMasks::ItemObjectType)
{
echo( "An item has entered this trigger.");
}
Parent::onEnterTrigger( %this, %trigger, %obj );
}edit:spelling
#4
This flag is used to test what entered the trigger since I don't know what $typemask to use (if there is one for rigidShape).
Then the triggercode:
Uncomment the echos and dump() if you want to see more functions, etc, you can use with this datablock.
05/12/2008 (2:53 pm)
OK. I tested it using rigidShape which is probably closer to what you need for a golf ball. I added a flag called 'flag' in the datablock which looks like:datablock RigidShapeData( GolfBall)
{
category = "RigidShape";
flag = 1;
.... more code here
};This flag is used to test what entered the trigger since I don't know what $typemask to use (if there is one for rigidShape).
Then the triggercode:
function ItemTrigger::onEnterTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the trigger.
%obj = %trigger.getObject(%i);
// echo( "%obj.getDatablock() = " @ %obj.getDatablock());
// echo( "%obj.getDatablock().flag = " @ %obj.getDatablock().flag);
// %obj.dump();
// Check if the %obj is an item.
if ( %obj.getDatablock().flag == 1)
{
echo( "A GOLF BALL has entered this trigger!!!!!!!");
}
else
{
echo( "Something else has entered this trigger. ::: " @ %obj);
}
Parent::onEnterTrigger(%this,%trigger,%obj);
}Uncomment the echos and dump() if you want to see more functions, etc, you can use with this datablock.
#5
how can disable collision with the character .
thanks a lot for your help.
05/12/2008 (3:36 pm)
Thanks a lot, yes with the rigidShape the triggers works , now i have another problem , it 's colliding with the character , with the item i used setCollisionTimeout( $player ); how can disable collision with the character .
thanks a lot for your help.
#6
For rigidShape you just check if it's a player and exit the function using return; I haven't tested this myself.
05/12/2008 (3:53 pm)
What is colliding with the player the rigidShape or the trigger?For rigidShape you just check if it's a player and exit the function using return; I haven't tested this myself.
function RigidShapeData::onCollision(%data, %obj, %col, %vec, %speed)
{
if ( %obj.getType() & TypeMasks::PlayerObjectType)
{
echo( "A player has entered this trigger.");
return;
}
#7
and i can solve with setCollisionTimeout( $player );
in your example RigidShapeData::onCollision(% ....
this function do not disable the colision , just send a message that there is a collision.
do you know any function to disable player collision with specific objet , in our case the rigidBody
something like this, %myPlayer.disableColission( $obj ) . or with the rigidShape
meanwhile , i think i can change the collision model, and reexport.
thanks mb
05/12/2008 (4:23 pm)
Yes , the rigidShape is colliding with the player, the same problem i had when i try with the item . and i can solve with setCollisionTimeout( $player );
in your example RigidShapeData::onCollision(% ....
this function do not disable the colision , just send a message that there is a collision.
do you know any function to disable player collision with specific objet , in our case the rigidBody
something like this, %myPlayer.disableColission( $obj ) . or with the rigidShape
meanwhile , i think i can change the collision model, and reexport.
thanks mb
Torque 3D Owner mb
A trigger I made a while back... might be more than you're asking but it shows how triggers work.