Adding forces on collision callback for CCD:
Posted: Thu Nov 26, 2020 11:24 pm
My problem is as follows: I have a ball of which I need fairly accurate, but fast, physics (basically a CCD solution)
The ball rolls at fairly high speed towards a box (part of compound body). On collision, I want a force to be applied on both the ball and the box (NOT along the normal) ; but the collision itself also has a restitution coefficient. I essentially want the force to be added immediately after the collision is processed e.g. the restitution is taken into account. I've tried directly adding a force in the callback, but this resulted in the colliding contact impulse computed by bullet being very small as the artificial force I added is already sufficient to seperate the bodies.
I'm using btMultiBody with CCD enabled for the ball.
Right now, I use the gContactAddedCallback to register the collision, and then set a flag for the next tick to add the
forces. This works better, as then bullet processes the entire collision and then only adds the forces for the next physics tick. This does however mean that the ball/sphere moves a bit after the collision is done at a velocity which is too low (and more importantly, in the wrong direction).
Is there any way to solve this problem nicely? Or do I just have to deal with it?
Unfortunately, the ball is often also touching the ground (for which all friction types are enabled) and in various states of spinning/sliding/rolling, so I cannot easily write an algorithm myself that from the hitfraction does this small extrapolation.
The ball rolls at fairly high speed towards a box (part of compound body). On collision, I want a force to be applied on both the ball and the box (NOT along the normal) ; but the collision itself also has a restitution coefficient. I essentially want the force to be added immediately after the collision is processed e.g. the restitution is taken into account. I've tried directly adding a force in the callback, but this resulted in the colliding contact impulse computed by bullet being very small as the artificial force I added is already sufficient to seperate the bodies.
I'm using btMultiBody with CCD enabled for the ball.
Right now, I use the gContactAddedCallback to register the collision, and then set a flag for the next tick to add the
forces. This works better, as then bullet processes the entire collision and then only adds the forces for the next physics tick. This does however mean that the ball/sphere moves a bit after the collision is done at a velocity which is too low (and more importantly, in the wrong direction).
Is there any way to solve this problem nicely? Or do I just have to deal with it?
Unfortunately, the ball is often also touching the ground (for which all friction types are enabled) and in various states of spinning/sliding/rolling, so I cannot easily write an algorithm myself that from the hitfraction does this small extrapolation.