SetCollisionMasks() help...
by Matt Van Gorkom · in Torque Game Builder · 03/05/2005 (1:58 pm) · 9 replies
I need some help understanding setCollisionMasks( groupMask/[layerMask] )
Reference docs don't give me (artist trying to be programmer too) enough info on what's going on, or perhaps I'm looking at it wrong.
I'm attempting to get my player to collide(and die) with objects in group 3, layer 8, but setCollisionMasks( 3, 8 ) doesn't work and I'd like to be able to specify multiple groups and layers.
I also noticed that in the spaceshooter tutorial Melv uses BIT(2). Why? I didn't find any reference to it in the reference docs.
EDIT:
Can I delay the collisionmask by a few millisecs so I can get the object out and away from the firing object first? I want the projectile to be able to kill even the player firing it.
Reference docs don't give me (artist trying to be programmer too) enough info on what's going on, or perhaps I'm looking at it wrong.
I'm attempting to get my player to collide(and die) with objects in group 3, layer 8, but setCollisionMasks( 3, 8 ) doesn't work and I'd like to be able to specify multiple groups and layers.
I also noticed that in the spaceshooter tutorial Melv uses BIT(2). Why? I didn't find any reference to it in the reference docs.
EDIT:
Can I delay the collisionmask by a few millisecs so I can get the object out and away from the firing object first? I want the projectile to be able to kill even the player firing it.
#2
Re: srcObj and dstObj in collisions, other people have said they find it helpful to re-name these sendingObj and receivingObj, respectively. The srcObj is the object which is causing the collision, and the destination object is the object against which a collision is occurring. If you have two moving objects that are configured to both send and receive collisions, there's really no good way to tell which is which, except by using some sort of tag to identify the objects.
I probably do this too much, but I can't help but describe how these systems are planned to change... in the future, the collision callback will probably change so that you can specify a collision callback function name per-object (though we'll still keep the general / default callback around, since that is convenient for many, many situations)
03/05/2005 (2:40 pm)
Yeah, magic. :) Just use BIT(3) and BIT(8), as Robert says. In the future, we'll probably make it so that if you don't specificy "BIT(X)", T2D will just interpret the parameters for you as bits. But for now, this is the way.Re: srcObj and dstObj in collisions, other people have said they find it helpful to re-name these sendingObj and receivingObj, respectively. The srcObj is the object which is causing the collision, and the destination object is the object against which a collision is occurring. If you have two moving objects that are configured to both send and receive collisions, there's really no good way to tell which is which, except by using some sort of tag to identify the objects.
I probably do this too much, but I can't help but describe how these systems are planned to change... in the future, the collision callback will probably change so that you can specify a collision callback function name per-object (though we'll still keep the general / default callback around, since that is convenient for many, many situations)
#3
Just set your collision mask with (BIT(3)|BIT(8)) and providing you have assigned the sprites to the correct groups and layers then you should be set.
03/05/2005 (2:41 pm)
I had trouble getting to grips with this. In the end I decided I didn't need to know how all the 'magic' works ;)Just set your collision mask with (BIT(3)|BIT(8)) and providing you have assigned the sprites to the correct groups and layers then you should be set.
#4
http://www.garagegames.com/mg/forums/result.thread.php?qt=26749
I'm sure I saw a post where someone showed how they delayed the collision by 250 millisecs so it could clear the area first...
03/05/2005 (3:03 pm)
Thanks for the help. I also found another thread on it here:http://www.garagegames.com/mg/forums/result.thread.php?qt=26749
I'm sure I saw a post where someone showed how they delayed the collision by 250 millisecs so it could clear the area first...
#5
I use that exact same idea for the typical "after-death brief invincibility" in Cloudburst.
03/05/2005 (3:26 pm)
Also, for disabling collision, you can use the setcollisionsupress (true) to turn off all collisions for that object. Just set it to true, then use a script schedule to turn it back off after a few milliseconds.I use that exact same idea for the typical "after-death brief invincibility" in Cloudburst.
#6
EDIT:
I find myself unable to make it work.
My code:
%cannon_ballProjectile.setCollisionSuppress( true ); // so as not to collide with barrel
schedule( 250, 0, %cannon_ballProjectile.setCollisionSuppress( false ) ); // activate collision
returns error: %cannon_ballProjectile.setCollisionSuppress( false ): Unknown command
My code:
%cannon_ballProjectile.setCollisionSuppress( true ); // so as not to collide with barrel
schedule( 250, 0, %cannon_ballProjectile.setCollisionSuppress( false ) ); // activate collision <-- note: without quotes around command
returns error: Call to setCollisionSuppress in player1Fire uses result of void function call
I know this more of a basic TorqueScript question, but I couldn't find sufficient documentation and copying examples I've found from TGE hasn't worked as you can see above.
03/05/2005 (3:29 pm)
Ah ha! I missed that in the tech docs. Thanks for the help. I was just going to move the linkpoint out further and leave it at that, but this is much better.EDIT:
I find myself unable to make it work.
My code:
%cannon_ballProjectile.setCollisionSuppress( true ); // so as not to collide with barrel
schedule( 250, 0, %cannon_ballProjectile.setCollisionSuppress( false ) ); // activate collision
returns error: %cannon_ballProjectile.setCollisionSuppress( false ): Unknown command
My code:
%cannon_ballProjectile.setCollisionSuppress( true ); // so as not to collide with barrel
schedule( 250, 0, %cannon_ballProjectile.setCollisionSuppress( false ) ); // activate collision <-- note: without quotes around command
returns error: Call to setCollisionSuppress in player1Fire uses result of void function call
I know this more of a basic TorqueScript question, but I couldn't find sufficient documentation and copying examples I've found from TGE hasn't worked as you can see above.
#7
%cannon_ballProjectile.schedule (250, setCollisionSuppress, false) ;
Using your method invokes a global schedule handler. You'd have to write that supress line inside a function, and then point the global scheduler to that. (At least, that's how it seems to work, those who are more TS savvy might say differently!)
Where if you invoke the local schedule method on the %cannon_Ballprojectile, you're just calling setcollisionsuppress as a part of that object. (There's no reason to have the '%cannon_ballProjectile' in front of it.) Also, you can't pass parameters in the same manner, they need to be given as seperate arguments in schedule.
03/05/2005 (4:13 pm)
Matt, you're almost there. Just change the schedule line to be:%cannon_ballProjectile.schedule (250, setCollisionSuppress, false) ;
Using your method invokes a global schedule handler. You'd have to write that supress line inside a function, and then point the global scheduler to that. (At least, that's how it seems to work, those who are more TS savvy might say differently!)
Where if you invoke the local schedule method on the %cannon_Ballprojectile, you're just calling setcollisionsuppress as a part of that object. (There's no reason to have the '%cannon_ballProjectile' in front of it.) Also, you can't pass parameters in the same manner, they need to be given as seperate arguments in schedule.
#8
03/05/2005 (4:22 pm)
Yes! That worked. Thank you. Yet one more step forward!
#9
03/05/2005 (11:34 pm)
David you are spot-on re: scheduling, just so you know.
Torque Owner Matt Van Gorkom
OK, got it, but not the rest :P