Intersection with static shape without collision

Official forum for the Chipmunk2D Physics Library.
Post Reply
jmdecombe
Posts: 7
Joined: Mon Feb 04, 2013 11:50 am
Contact:

Intersection with static shape without collision

Post by jmdecombe »

First off, thanks for the great physics engine. I want to confirm that I am on the right track for an application where the user controls a character that can move in and out of areas, and whose state can change simply by virtue of entering or leaving an area.

The idea is to add the character to the space as a regular body with a regular shape, and to attach the various area shapes to the static body of the space, then add these shapes to the space as well. Then, each static shape thus added is marked as a sensor, and collision callbacks are defined between the character and the area shapes, whose begin() callback returns FALSE. Thus, it is possible to determine when the character enters an area, in begin(), then when it leaves the area upon calling of separate(). However, the character can simply walk over these areas (not bounce off them) since intersection is detected but no collision is actually computed.

Is that a fair assessment of how things would indeed work, and am I on the right track indeed? Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Intersection with static shape without collision

Post by slembcke »

Yeah, that would work fine. I've done similar things before. One thing to note is that the return value for begin/pre-solve callbacks of sensors is ignored, though I always return false from them to be consistent.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jmdecombe
Posts: 7
Joined: Mon Feb 04, 2013 11:50 am
Contact:

Re: Intersection with static shape without collision

Post by jmdecombe »

That's good to know, thanks a lot. I am also optimizing by having the moving characters all in the same layer but also in the layer of those areas with which they can actually interact, instead of all areas, so as to limit collision testing. Cheers!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Intersection with static shape without collision

Post by slembcke »

Sensors actually don't bother checking for overlap unless there is a collision handler callback that will be called. The bigger performance problem is that having a lot of constantly overlapping shapes can slow down the spatial indexing. That is all processed before layers, groups or callbacks. That said, I don't expect you'll see performance issues unless you plan on having thousands of moving shapes. I wouldn't worry about it up front.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jmdecombe
Posts: 7
Joined: Mon Feb 04, 2013 11:50 am
Contact:

Re: Intersection with static shape without collision

Post by jmdecombe »

Ha! Always a good reminder to never optimize too soon, unless there is supporting evidence (profiling or usability) for a need to do so. Your responsiveness is much appreciated. Cheers!
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests