Things I wish I had known about physics: (3 magical functions)

Hi folks, thought I would dump out what some info…related to my battles in getting my first game put together, specifically related to physics,which I think was my main bottleneck in terms of performance.



setAccuracy: ← Magic Function

Finding this was my first break through:

Solved issues where the objects were passing through other objects, or bouncing oddly.

yes…the higher accuracy the slower the game. (was not an issue for me on pc, but on

andriod this became as massive issue in terms of performance and game play, still I could not keep it accurate enough and playable on android…)

This is mentioned in the tutorial docs (not sure it was present when I first started playing with jme3)



setMaxSubSteps: ← Magic function. :slight_smile:

FPS compensation function…(enable physics to work at lower fps numbers)

Enables the physics system to adjust for lower fps/physics bound operations. This Defaults to 4.

Solved the issue of of crappy fps on android, with ‘high accuracy’ (the game is now playable :)…now I just need to finish it.

This is NOT in the tutorials/intro Docs (imho…this should be mentioned, it was a world changer for me at least).

There are some posts that mention this function…which is how I found it.



setCcdMotionThreshold(): ← Important function for fast moving objects.

I knew about this from the start, but didnt realy seem to help all that much until the above discoveries.

IMHO? this really only applies to moving objects.

Solved Issue: Where objects moving objects would sometimes get stuck with other, or pass through, or bounce weirdly.

This is in the intro docs.



While my game is not nearly close to being done yet. The discover of the setMaxSubSteps has removed my last stumbling block, and hopefully can now focus on assets, rather then technical issues :slight_smile:



Cheers

14 Likes

cool, cant say i’ve really used any of them either, will have to check them out!



Physics can be a pain at first, but once you get the hang of it, you get achieve some really awesome things with it :slight_smile:

setCcdMotionThreshold(): is only in the native bullet binding as far as I remember

@EmpirePhoenix said:
setCcdMotionThreshold(): is only in the native bullet binding as far as I remember

No its also in jbullet but its a bit wonky as the sweepTest is.

Great post, maybe it will also solve some of my issues in my previous project! :slight_smile:

It’s just shame that I am already on another (more simple) project, where I don’t use physics. :smiley:

@danomano said:
Solved the issue of of crappy fps on android, with 'high accuracy' (the game is now playable :)..now I just need to finish it.

This part worries me a bit. You are aware that the accuracy is basically a framerate yeah? If you set the accuracy to e.g. 1/60 and get a framerate of 30fps on the device then you MUST have a substeps number of "2" or the physics will only be half as fast. Effectively you only lessen the load by making your physics "non-realtime" and less accurate at the same time.

thanks for these informations :slight_smile:



Maybe this will solve a rare condition in my game (moebius) where some thrown blocks still pass through the floor when they have too much momentum.

@danomano Tks for the post. I trully believe it will be useful for me when I get back to my game.

tank for the tips :wink:

Good tips, very useful to me.

I added your comments to the physics wiki too. Some were already there (maybe you added them yourself), but you mentioned some useful examples. Thanks!

3 Likes

I have struggled with these problems, too. These posts might be of interest:

[SOLVED] Ball sinking into floor in low fps situations

Does speed of movement also influence collision detection?

1 Like

One other tip, avoid Mesh collision shapes. It may be obvious to some, but a collection of native shapes in a CompoundCollisionShape is much faster than a static or dynamic mesh shape. I was surprised how much my framerate increased when I made my mesh collision shape a few boxes and spheres.

2 Likes