Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Getting physics objects to sleep

Author
Message
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Sep 2014 03:13
I am creating the level editor for a game and can build structures using physics enabled sprites (by picking them up and moving them around with the mouse - mousewheel rotates the sprite - it's quite cool!). However the structures fail to remain standing. It is as though the objects continue to move almost imperceptibly until after several seconds or minutes, it all comes crashing down.

Is there any way to adjust how sensitive BOX2d is (using tier 1 AppGameKit commands) to sprite movement before letting sprites sleep? I tried setting SetPhysicsSleeping(1), and SetPhysicsSleeping(0) thinking that maybe the default setting was incorrectly reported, alas this appears to make no difference.

Example:



2 minutes later:



I have physics scale at 0.2, and have played around with friction, restitution and mass settings but am struggling to get these pesky planks to settle down! I would appreciate your thoughts.

Thank you!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Sep 2014 10:32 Edited at: 12th Sep 2014 10:50
If it's purely for building the levels what I would do is to turn them into static sprites until the user clicks on them. Basically you delete physics for the sprite and reset it to 1-Static then when the user presses on a sprite to adjust it reset it to 2-Dynamic and add a mouse joint. Here is some old code for resetting physics for a sprite but I think the delete physics command works fine now. EDIT: this actually creates a new sprite just like the old one and returns its ID...



You could alternatively play with physics scale or damping to get these minute movements under control... not sure what else would help but I used the method I describe above a few times for level editors and it works fine. Alternatively I think linear and angular damping might help in the editor.

EDIT2: Another thought, make sure you don't set your Restitution too high. That could keep things bouncing around for a bit. Last resort though... I doubt you've messed with that to the extent it would cause problems.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Sep 2014 11:01
Thanks baxslash. I was hoping I wouldn't have to manually turn the dynamic on and off, but it's no biggy to do I suppose. Thanks for the suggestion - I'll implement it this evening.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Sep 2014 11:15
You could try the damping first. If you ramp up angular and linear damping it will stop any little movements like you are describing. The only problem with switching physics off when the user lets go is that it might leave your structure in a way that will still collapse when the game starts. I would be tempted to turn objects static only when their linear and angular velocity goes below a certain value (IE. nearly completely still).
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 12th Sep 2014 12:49
If you turn off physics, and design the level, what happens when you turn physics back on? It all comes tumbeling down.

Best to have physics enabled, and then add a set physics on/off for each object, so that you can temporarily lock objects in place, while placing other objects on top of each others for stability, then turn physics back on. Maybe make the locked ones glow red while in "locked mode".

In real life, you can not expect 4 table legs to stand still on the floor, while you try to add the tabletop...

If the 4 legs are "glued" to the floor though, it's easy to add the table top.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Sep 2014 13:02
Great ideas chaps. I'll tinker more this evening (would be nice if we could simply adjust the sensitivity of box2d's sleep functionality though - I might add to a wish list).

Thanks for your help!

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 12th Sep 2014 15:50
Didn't read everything but, StepPhysics(0) ?

My hovercraft is full of eels
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Sep 2014 16:01
I was thinking about trying to use StepPhysics(0) if the islandcount dropped below a certain value, but dismissed the idea (as once set, the islandcount would never go back up again! Lol).

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 12th Sep 2014 17:04
Give them warm milk and tuck them in?

Sorry, I could not help myself :p

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Sep 2014 17:34

Login to post a reply

Server time is: 2024-04-26 08:47:32
Your offset time is: 2024-04-26 08:47:32