Game Development Community

Disable specific collisions?

by Mr Zurkon · in iTorque 2D · 07/11/2011 (11:56 am) · 15 replies

Is there a way to disable specific collisions? Let's say I have two Car-instances that I don't want to be able to collide with each other, but I still want it to be able to collide with other non-Car objects.

1. Is there a way to make an object not collide with other instances of the same type?
2. How can I keep physics (for movement), but keep the object from being able to stop when it hits something?

#1
07/11/2011 (12:13 pm)
Likely modify the collision layers/groups for the specific object.
#2
07/11/2011 (12:16 pm)
The problem with the collision layer-solution is that I'll have to create an unique collision layer for every instance (instead of just disabling it). I'll probably do this if I can't find any other solution.

Are collision layers the same as layers? Or is that something specific to collision?
#3
07/11/2011 (1:09 pm)
Just use a collision group - assign a group to your car class and then set a collision group that doesn't include the car group. You can use the editor to work out the collision group mask - it's easier.
#4
07/12/2011 (6:28 am)
Spot on. Collision groups are what you are looking for. They do not need to be unique for every instance. You can create new instances with that property set, just like everything else.
#5
07/12/2011 (9:14 am)
not to jump in here, but what would be the difference (if any) of using a class over a group or vice versa regarding collisions?




#6
07/12/2011 (9:18 am)
Rennie, you could check the classes but the advantage of groups is that the engine will exclude those objects from colliding for you - greatly improving performance as you don't have the overhead of the collision detection and the callback into your script code.
#7
07/12/2011 (9:53 am)
ahh right.
So I guess it is just a matter of setting the group number then onCollision

if(%dstObject.group == 7)...


???
#8
07/12/2011 (10:25 am)
No. It's automatic. You set the group as a field for the object and it the collision happens in the background. onCollision will not even be called.
#9
07/12/2011 (11:49 am)
hmm, sounds good. must research.

chanks!!!




#10
07/13/2011 (9:29 am)
i've got it working, but I have some questions;

1. Where does collision groups get these numbers from? If I set an object's collision groups to 1 and 4, the Collision Group-value I get is 18. It made it a bit cumbersome figuring out what values I had to use.

2. What if I want something to have collision callback, physics enabled (so I can use movement functions) - but I don't want them to actually collide/stop each other? I just want the game to tell me when they're colliding, and not do anything.
#11
07/13/2011 (6:11 pm)
re 2. Just do not have any reaction in the collision function. If physics send and receive are on there may be a reaction (bounce off each other, but if just usesPhysics is true and you do not tell the onCollision function to do anything regarding these two groups then nothing will happen.
#12
07/14/2011 (7:20 am)
I'm not sure I get what you mean. I still need the objects to be able to tell when they're colliding with each other, I just don't want them to stop (which seems to be something of a default thing if you have physics enabled) when colliding. My onCollision-function doesn't do anything yet except print a warning to me to tell me they've collided.
#13
07/14/2011 (6:40 pm)
right there are 3 separate things here.

1. Uses Physics - this simply allows an object to move.
2. Phsyics Send/Recive - this/these, if on make an object, bumping to another object that sends and or receives to bounce off each other. If you do not want them to bounce off each other, make sure both of these are off.
3. collisions - in here you have your printed warning.


#14
07/15/2011 (12:35 pm)
I was not aware of the CollisionPhysics properties. I should have looked for this right away. Thanks!
#15
07/18/2011 (7:54 am)
::))((