Pause a dynamic physics object when off screen

I have 7 of the same dynamic physics circle objects and 7 of the same static physics square objects. Sometimes some of them are off screen. I was wondering if there is a way to pause or stop the physics behavior of the ones that are off screen?

My expected result would be that they pause completely.

But what happens is off screen, they don’t pause. So also any sounds they make or colors they change when they collide with a sqare keep happening.

I did try to use sleep is ok, sleep is not ok in behavior settings and some action events. Also that with “for each”. But it seemed that even though they knew sleep was ok, they didn’t want to. But it’s possible I was using it incorrectly.

For now, I made a workaround to only change colors or play sounds if they are in a boundary.

But testing it by resizing the screen indicates that the calculations for physics are still going on for each ball object. So I was just wondering: can they pause completely? This is not a big deal or a huge priority because this is not a project I’m making. It was just something I threw together to test performance of a device after reading another post on the forum. But I am curious and would like to know so if anyone has the time to answer, tyvm.

Edit Or should this be something solved by not creating/destroying off screen objects?

Here are some suggestions:

  1. You should install the “Is On Screen” extension. Then add it to the object behaviors, and you could do it like this:
    If [Object] is on Screen (Condition), Activate the behavior {PhysicsObject}: yes
    {Inverted}If [Object] is on Screen (Condition), Activate the behavior {PhysicsObject}: no

  2. Or if you do not want to deactivate the object’s physics behavior, you could do something like this:
    {Inverted} If [Object] is on Screen (Condition), Set object to static
    But it will be difficult to bring it back to the screen, because it is static

2 Likes

Hey buddy, thanks a lot! I loved your suggestion and got it implemented into my project. It works perfectly for my use case (since I don’t need the objects to come back to the screen on their own, just if the screen is resized they need to come back to life). Based on your advice under point #2, I did add an event to reset the offscreen objects back to their original position. That way if they come back on screen they will behave as expected.

I am glad that this is helpful. Happy to help