Two Outstanding Issues

Post Reply
Xenoprimate
Posts: 14
Joined: Fri Jun 26, 2015 4:59 pm

Two Outstanding Issues

Post by Xenoprimate »

Hi all, the game I've been working on for the past 2.5 years is nearing completion; but there are two outstanding physics issues that I just can't seem to resolve, and I'd really appreciate anyone's help here in getting them fixed. I'm happy to offer a free copy of the game on Steam to you all also (though I know that's not much incentive ^^) for your time. :)

Either way, I'll just get down to it:

Issue #1: Resting 'Vibration' Due to Gravity

Here's a screenshot of my game:
gravVib.png
gravVib.png (1.16 MiB) Viewed 12463 times
Basically, the problem is that at rest the ball will start to 'vibrate' on the floor. It appears that acceleration due to gravity keeps increasing the velocity of the ball (its velocity increases each frame, until the downward component is getting very large). Eventually, left long enough, the ball will penetrate through the floor/platform, even though CCD is enabled on the ball.

Here's a Gfycat that demonstrates the problem: https://gfycat.com/MadOblongChameleon

The relevant parameters in the simulation are as follows:

Global

Tick Max Substeps: 10
Tick Internal Tickrate: 120 fps (Fixed Time Step = (1.0f / 120.0f))
Game Framerate: 60 fps
Gravity: (0.0f, 490.5f, 0.0f)

Ball

Mass: 1.0f
Restitution: 0.5f
Linear Damping: 0.45f
Angular Damping: 1.0f
Friction: 0.15f
Rolling Friction: 0.15f
Collision Radius: 4.0f
CCD Motion Threshold: 0.5f
CCD Collision Radius: 0.04f

All Other Geometry (Including Floor)

Flags: defaultFlags | btCollisionObject::CF_KINEMATIC_OBJECT
Gravity: (0.0f, 0.0f, 0.0f)
Mass: 1000f
Restitution: 0.5f
Linear Damping: 0.05f
Angular Damping: 0.05f
Friction: 0.15f
Rolling Friction: 0.15f

Disabling CCD on the ball doesn't seem to make any difference. I've noticed that changing the ball's mass has an effect (heavier balls penetrate through the ground a lot quicker)- but at any mass the ball will become 'stuck' in the floor fairly fast. In fact, when I lower the ball mass, the ball doesn't vibrate anymore but just gets completely stuck at its position on the floor.

I don't really understand what I'm doing wrong: I can't understand how any rigid body can get 'stuck' in another in Bullet, let alone pass right through- and as far as I can tell my values/properties are pretty normal? Hopefully someone can shed some light on this one.

Issue #2: Framerate Drops in Certain Scenarios

I've noticed that my framerate suffers when the ball is travelling in an area that has a 'cluster' of geometry. Here's a screenshot of a level that exhibits this problem:
fpsDrop.png
fpsDrop.png (621.86 KiB) Viewed 12463 times
Each of those rings swivel independently. I think the problem occurs when the ball inside the AABB of all of those rings simultaneously.

Here's a gfycat demonstrating the framerate drop: https://gfycat.com/SociableSlushyHorse

You can see two distinct moments where the framerate drops in that gif.

The parameters are as I described above in problem #1. I'll just add that I'm also using collision groups, here is how they're set up:

Code: Select all

enum CollisionType : short {
	COL_NOTHING = 0,
	COL_EVERYTHING_ELSE = BIT(0),
	COL_WALL = BIT(1),
};

// Ball is added with the following call:
dynamicsWorld->addRigidBody(result, COL_EVERYTHING_ELSE, COL_WALL | COL_EVERYTHING_ELSE);

// Rings/walls/floors/all other 'level geometry' added with the following call:
dynamicsWorld->addRigidBody(result, COL_WALL, COL_EVERYTHING_ELSE);
Anyway, I know I'm using a reasonably high internal tickrate (120FPS) but I don't think there's that much to resolve here- it seems like there's a problem with my setup of the world; almost like the collision flags are being ignored maybe? I'm only guessing though. I'd rather not reduce the internal tickrate as the ball physics begins to reduce in quality quite quickly.

----------

If there's anything more you need to know about the way I've set my world/simulation up, please let me know.

Thank you all for your time. It is really appreciated. I'm willing to try any suggestions you may have.
Xcoder79
Posts: 42
Joined: Sun Aug 07, 2011 5:27 am

Re: Two Outstanding Issues

Post by Xcoder79 »

Hi,


Have you tried setting the gravity value to something lower then 450.5f inside global.

Thx, hope this helps
Xenoprimate
Posts: 14
Joined: Fri Jun 26, 2015 4:59 pm

Re: Two Outstanding Issues

Post by Xenoprimate »

Thanks for the suggestion Xcoder79.

I just tried it and it made no difference (other than the ball feeling more floaty, obviously).

The value of 490.5f comes from 9.81f * 50.0f; 50.0f is the dimension of one metre in my game.
kermado
Posts: 20
Joined: Tue Jan 12, 2016 11:20 am

Re: Two Outstanding Issues

Post by kermado »

What is the type of your level geometry (in particular, what is the geometry type for your rings)?
Xenoprimate
Posts: 14
Joined: Fri Jun 26, 2015 4:59 pm

Re: Two Outstanding Issues

Post by Xenoprimate »

kermado wrote:What is the type of your level geometry (in particular, what is the geometry type for your rings)?
Each ring is a btCompoundShape constructed of (warped) trapezoidal prisms. Is there a better way?

The rest of the geometry is either a compound shape (for complex meshes) or simpler boxes/spheres where appropriate.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Two Outstanding Issues

Post by drleviathan »

For problem #1: I would suggest setting the restitutions to 0.0, or as low as possible, everywhere where the ball does not need to bounce. If that is not acceptable then maybe you need to reduce the gravity as Xcoder79 suggests (why is it so high anyway?).

For problem #2: there is a way to dump the timing of a Bullet simulation frame to get more info where the CPU cycles are going when it starts to lag. Look for info about CProfileManager::dumpAll(). But... have you correlated your bad frame rates with using continuous collision detection (CCD) on the ball? If you're using an old version of Bullet then this could be your problem and the good news would be: there was a fix merged into Bullet back in late April 2016 that speeds things up.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Two Outstanding Issues

Post by Dirk Gregorius »

The first issue looks a bit like you are loosing contact points. What collision margin do you use? You would need to scale this one as well. I think that Bullet also uses a distance threshold where it break old contact points. You would need to check that this tolerance works with your units.

One thing that might be an easier fix would be to run Bullet in MKS and do the conversion from/to your unit system in your interface to Bullet. We did this in Half-Life 2 and it worked well.
Xenoprimate
Posts: 14
Joined: Fri Jun 26, 2015 4:59 pm

Re: Two Outstanding Issues

Post by Xenoprimate »

Dirk Gregorius wrote:The first issue looks a bit like you are loosing contact points. What collision margin do you use? You would need to scale this one as well. I think that Bullet also uses a distance threshold where it break old contact points. You would need to check that this tolerance works with your units.
After a couple of hours of tweaking values (including the ones you mentioned) I actually managed to get somewhere acceptable. Something that I noticed however is that although I thought I had CCD enabled, the ball is capable of dropping right through the geometry- I still haven't really got a fix for this, except setting the static geometry's mass to PositiveInfinity seems to have ameliorated it (as far as I can tell via testing).
drleviathan wrote:For problem #2: there is a way to dump the timing of a Bullet simulation frame to get more info where the CPU cycles are going when it starts to lag. Look for info about CProfileManager::dumpAll(). But... have you correlated your bad frame rates with using continuous collision detection (CCD) on the ball? If you're using an old version of Bullet then this could be your problem and the good news would be: there was a fix merged into Bullet back in late April 2016 that speeds things up.
Thanks for the advice; I'm going to download a more recent build later on and try it out- but that'll probably take me a short while to get running.

Thank you all for the support so far, I really appreciate it. (By the way, if you'd like a copy of the game at all, send me a PM)

-------------------------------------------------------------------

Edit: Updating to the newer version of bullet worked to solve the FPS issue. I think the github issue you linked was exactly the problem I was encountering (CCD + large btCompounds). Thank you so much. :)
Post Reply