How do I make physics objects to calm down and go to sleep

0 favourites
  • 11 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Sorry if this a silly question, I'm new to physics.

    I need to be able to put two square physics boxes on top of each other, but they keep shaking and sliding.

    Debug mode shows that even when one box is lying on the floor, it never goes into Sleeping mode, its velocity is constantly changing a little.

    This happens when either the box or the floor has Elasticity>0.

    But I want boxes to bounce when dropped, so I need elasticity.

    Is there any way to fix this?

    CAPX

  • Hi dop,

    I can't give you a full solution, but I can offer some improvements. (I'm pretty much a physics newbie too)

    The resting on the floor problem can be improved greatly by using the native size of your floor object, rather than stretching it at runtime, due to rounding errors.

    The janky movement when dragging is caused by using a non physics method of moving around the object. As mentioned on the manual page, this is normally not recommended (drag and drop can't take into account collisions and center of gravity rotations ect, so the two behaviors will fight each other to position the object).

    I'm not sure whats going on with the two boxes resting on each other. Again try to make sure that the native size of the object matches what is placed in the layout editor to minimize rounding errors, although this didn't seem to help in this particular example.

  • Thanks, oosyrag!

    I tried native sizes and I tried setting "Collision Mask=Bounding box" for the floor and boxes, unfortunately it didn't help.

    As for the drag&drop, I used it just for this demo, in a real game I have a different control system.

    I am trying to do something with events - constantly checking if the box stays in the same place for longer than 0.1s, then changing its elasticity to 0, or even set it as Immovable, but it doesn't work very well. I really hope there is an easier solution.

  • Physics is quirky in general. You could try a different physics behavior. There's another box2d one and a chipmunk one. Both were made after a dissatisfaction with the default one. Not sure if they solve that issue. I know the chipmunk one has its own set of issues.

  • Thanks R0J0hound,

    Chipmonk seems to work much better! There is no shaking or sliding and objects go to sleep pretty quickly.

    The only problem I noticed so far is that there are no properties displayed in Debug mode..

    I'm a bit cautious about using such complex custom behavior in my game. Do you know if there are any issues with it working on different mobile platforms?

  • Well one of the main advantages with construct/html5 is that you can at least be pretty confident in the consistency in behavior across platforms, if not performance or packaging process.

  • I never added anything to the behavior for the debugger or save/load. The only issues would trying to do something the chipmunk library doesn't allow. I wasn't able to protect against all cases. Normal use should be fine. Also the collisions seem to be spongier than box2d which may or may not be an issue.

    I concur with what ossyrag said, behaviors are just JavaScript so they should run the same across anything that runs C2.

  • You can disable physics for objects, then turn it back on when needed. That is what I usually do. For example if absolute y speed is less than 1 disable it and it should sit on another object as expected. I do it all the time, almost every game.

    When to turn it back on depends on what it is you're trying to do. As soon as you touch it to drag it, when another object is close enough and about to hit it, and so on

    If the problem is only not sitting on top of another box, just increasing Physics world stepping, velocity and position, to something like 15 and 10 may fix it.

  • Thanks, BadMario!

    I have many boxes on the layout that may move chaotically and fall on each other all the time, so turning Physics on/off is not an option. I only turn it off when box is dragged.

    I am trying to make stationary boxes Immovable. If this doesn't work well, I'll probably have to switch to ChipMonk.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dop2000 to solve your problem set the bottom box density more than the top one density

    top density = 2

    bottom density = 200

    that will fix the sure you having

  • wizdigitech

    What if there are many boxes piled at different angles? I also need to throw them and boxes should bounce and knock off other boxes etc.. So no, I can't change their density.

    I already have a solution in place with temporary setting boxes as Immovable. It seems to be working quite well. If I have any issues with it, I always have an option of switching to ChipMonk.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)