Page 1 of 1

space sleeping and shape->sensor

Posted: Thu Aug 19, 2010 9:24 pm
by Mark
Hi,

I set my space->sleepTimeThreshold to, say 1 second, and I've got a couple of sensors( 1 body + 1 shape) that I have sitting in one place, and when I pass another (1 body + 1 shape) over it, they don't wake up, or cause a collision. I see that the step checks objects for their kinetic energy before deciding whether to have them sleep or activate, but I'm wondering if there's a way to have the sensors sleep, but also 'look' for collisions? Does that make sense? I'm basically asking if there is a way to have a stationary sensor be woken up by another (moving) body/shape?

Of course, it works when I don't set the sleepTimeThreshold, and everything stays awake. Is there any way to have my cake and eat it too?

Thanks,

Mark

Re: space sleeping and shape->sensor

Posted: Fri Aug 20, 2010 9:07 am
by slembcke
The sensor callbacks should still function though right? In that case you can just call cpBodyActivate() in a post step callback. Thinking about it now, I'm not sure if it's safe to reactivate bodies from a callback, I should double check and document that.

Re: space sleeping and shape->sensor

Posted: Fri Aug 20, 2010 4:55 pm
by Mark
Scott,

Oooh, thank you, I missed that when I was perusing your code. I'm, of course, not using your engine correctly. Currently I've got two types of sensors that I move manually, so BOTH of them were sleeping, while I was manually moving them around, which was, of course, not even calling 'begin' when the two shapes overlapped. So now, when I manually move the shape, I simply call cpBodyActivate, which allows it to trigger the 'begin', and I can activate my other sensor. I'll figure out a better, even 'right' way to do it later, but for now, it works. Thank you!

The only thing is, I'm finding that with this method, begin and preSolve are called every step while the sensors are touching. I'm getting around that by setting my own state var for the sensors, but .. would anyone have any suggestions for moving the physics bodies manually and keeping it awake based on my movement(basically according to sprite movement)? Currently I'm doing this each step:

Code: Select all

cpBodySetPos(body, sprite.position);
cpBodySetAngle(body, RADS(sprite.rotation) );
-Mark

Re: space sleeping and shape->sensor

Posted: Sun Aug 22, 2010 6:23 pm
by slembcke
Hrm. Begin should not be getting called each time. I'll have to look into that.

If you want it to only wake up when you move the shape, you should check if the new position is the same as the old position first.

Re: space sleeping and shape->sensor

Posted: Fri Oct 01, 2010 3:18 pm
by slembcke
Sorry about the long delay, but this should be fixed now. (See http://www.slembcke.net/forums/viewtopic.php?f=1&t=1163 for more info)

Re: space sleeping and shape->sensor

Posted: Mon Oct 04, 2010 2:57 pm
by Mark
Scott,

Just to confirm, that seems to have fixed my issue with the _begin callback getting repeatedly called even after rejecting.

theMan->you . Thank you!

-Mark