Excluding groups

Official forum for the Chipmunk2D Physics Library.
Post Reply
AntonyDream
Posts: 3
Joined: Sat Sep 28, 2013 12:43 am
Contact:

Excluding groups

Post by AntonyDream »

Is it possible to exclude one group of shapes from collision with cpSpaceSegmentQueryFirst without using different layers?

I'm trying to implement laser ray shooting and don't want to hit shooter's shape while it still can collide with other shapes.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Excluding groups

Post by slembcke »

Yes. It's actually the same answer to a slightly different question from this morning here:
http://chipmunk-physics.net/forum/viewt ... 076#p12907

You use the "group" property of a shape actually. Your question was so close to answering itself. ;)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
AntonyDream
Posts: 3
Joined: Sat Sep 28, 2013 12:43 am
Contact:

Re: Excluding groups

Post by AntonyDream »

Omg, I just thought this property works in opposite way :D
Thanks for make it clear for me!

By the way, if I ever want to hit only one group except others, what should I use in this case?
drey08
Posts: 15
Joined: Mon Oct 28, 2013 10:55 pm
Contact:

Re: Excluding groups

Post by drey08 »

AntonyDream wrote:Omg, I just thought this property works in opposite way :D
Thanks for make it clear for me!

By the way, if I ever want to hit only one group except others, what should I use in this case?
Wait, so using a group in a cpSpaceSegmentQueryFirst call will exclude that group? If that's the case then I thought it was the opposite as well.
AntonyDream
Posts: 3
Joined: Sat Sep 28, 2013 12:43 am
Contact:

Re: Excluding groups

Post by AntonyDream »

drey08 wrote: Wait, so using a group in a cpSpaceSegmentQueryFirst call will exclude that group? If that's the case then I thought it was the opposite as well.
Yep, that was an unexpected turn for me too :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Excluding groups

Post by slembcke »

That's a common misconception actually. :-\ While it's intuitive that the layers work the same for queries and collisions, people often think that groups work the opposite way.

@AnthonyDream If you want it to work the other way around, you can always implement the callback based iterator and filter them yourself. The "nearest" and "first" versions of the query functions don't really do anything particularly special**. Zamaster has a good description here: http://chipmunk-physics.net/forum/viewt ... 916#p12906

** Not exactly true. It's built on the spatial indexing function which work similarly, but make it possible to exit a query early. https://github.com/slembcke/Chipmunk2D/ ... ery.c#L111
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests