How to get sprites only colliding with specific other sprites
by Rob Segal · in Torque Game Builder · 10/12/2006 (10:20 am) · 6 replies
So I'm pretty sure I know the answer to this but I need some kind of confirmation to be sure. Say I have a bunch of sprites repesenting some enemies and a single sprite representing the player. I want to make the enemies only collide with the player but not with each other. I would have to set collision masks in both parties to do this right?
The appearance I want to have is that the enemies have the ability to overlap each other when moving around on screen but will not overlap the player. They will visibly collide with the player sprite.
The appearance I want to have is that the enemies have the ability to overlap each other when moving around on screen but will not overlap the player. They will visibly collide with the player sprite.
#2
Collision Groups and Collision Layers (set in the Collision rollout in the Edit tab) are used by the collision sender to check against a receiver's Group and Layer (set in the Scene Object rollout in the Edit tab). For a collision to occur the receiver's Layer must be in the sender's Collision Layers -and- the receiver's Group must be in the sender's Collision Groups.
Physics send checked means that this object will have a physics response when it successfully collides as a sender.
Physics receive means this object will have a physics response when it successfully collides as a receiver.
These are some of the trickiest things to figure out about the collision system in TGB and part of that admittedly has to do with the language associated with it. Once this all makes sense to you there are all sorts of neat things you can do with the collision system. I hope this was helpful.
10/13/2006 (7:03 pm)
Also, there is some general confusion around the send/receive physics settings. They use the same terminology as the send/receive collision settings but work entirely different. As you're testing out collisions, as Tom suggested, note that...Collision Groups and Collision Layers (set in the Collision rollout in the Edit tab) are used by the collision sender to check against a receiver's Group and Layer (set in the Scene Object rollout in the Edit tab). For a collision to occur the receiver's Layer must be in the sender's Collision Layers -and- the receiver's Group must be in the sender's Collision Groups.
Physics send checked means that this object will have a physics response when it successfully collides as a sender.
Physics receive means this object will have a physics response when it successfully collides as a receiver.
These are some of the trickiest things to figure out about the collision system in TGB and part of that admittedly has to do with the language associated with it. Once this all makes sense to you there are all sorts of neat things you can do with the collision system. I hope this was helpful.
#3
However when I get my enemies moving around they still collide with each other and don't overlap. Based on the script code I have here my understanding is that the enemies should not be colliding with each other but should collide with any objects on layer 1 and graph group 1. Am I interpreting this all correctly?
10/13/2006 (11:09 pm)
Thanks for the replies guys. It's making more sense slowly but I just can't seem to get the effect I want. Here is my script code for spawning enemies...%enemy = new t2dStaticSprite()
{
scenegraph = sgMain;
class = "Enemy";
};
%enemy.setLayer(2);
%enemy.setGraphGroup(2);
%enemy.setImageMap("img_GoatOnPole");
%enemy.setCollisionActive(true, false);
%enemy.setCollisionPhysics(false, false);
%enemy.setCollisionMask( BIT(1), BIT(1) );
%enemy.setCollisionMaxIterations(2);However when I get my enemies moving around they still collide with each other and don't overlap. Based on the script code I have here my understanding is that the enemies should not be colliding with each other but should collide with any objects on layer 1 and graph group 1. Am I interpreting this all correctly?
#4
should be
:)
10/14/2006 (4:00 am)
If this is direct code then%enemy.setCollisionMask( BIT(1), BIT(1) );
should be
%enemy.setCollisionMask[b]s[/b]( BIT(1), BIT(1) );
:)
#5
10/14/2006 (4:46 pm)
Thanks Matt. You are correct that was direct code. I've made the appropriate change but the problem still seems to be persisting. Any other thoughts?
#6
10/14/2006 (7:33 pm)
Ah yes... as is usually the case it's all my fault. Turns out my script code as I have written it above wasn't even being called at all. I'm such a foolish boy. Things indeed are working properly now. Much obliged for the help.
Associate Tom Eastman (Eastbeast314)
I think the documentation has some basic examples of collision setups and some of the tutorials do too. I'd recommend just creating a simple project, set some initial velocities and collision parameters, and seeing what does what. It can definitely be confusing until you whip out the old scientific process and try it out it.