Either way, I'll just get down to it:
Issue #1: Resting 'Vibration' Due to Gravity
Here's a screenshot of my game:
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:
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);
----------
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.