Using constraints to calculate Raycast Vehicle friction
Posted: Mon Aug 15, 2016 6:50 pm
So, the problem with vanilla btRaycastVehicle is that whenever you try to park a car on slope, car keeps rolling down slightly.
To find out impulse needed to stop the wheel from moving sideways, btRaycastVehicle uses resolveSingleBilateral(src) method.
To apply brakes, the impulse is found through calcRollingFriction (src).
Combining this 2 approaches does not work completely well. Sideways impulse is pretty damn correct and it works good for all 4 wheels, but this calcRollingFriction does not stop the car from slowly rolling from a slope.
Things I tried so far:
1. Using resolveSingleBilateral both for side impulse and for forward impulse. This brings jittering and somehow fails to do the job in the end. It can stop the car eventually, but only on a level ground.
2. Using resolveSingleBilateral in the direction that follows current wheel movement, then projecting the backward impulse on side and front vector of the wheel. This one ended up failing aswel. Then I found out that for some reason, even if you apply the result of resolveSingleBilateral in the direction of movement, the car still keeps rolling off a slope.
Then I got back to good old Kester Maddock's document Vehicle Simulation With Bullet, section Friction Model, and there he describes approach of implementing a constraint for that. Howewer I couldn't make his drafty code working.
Since then I am thinking whether it is possible to use any of bullet's constraints as a base to make a friction constraint. Basically, what I need is a constraint that prevents moving on specific axle, which can be called like "Point to plane" constraint, which must have configurable mixing force (like with 0 it doesn't act at all, and with 1 it stops moving on that axle). Also I need to change that limiting axle with every simulation step, for obvious reasons.
So can someone guide me where to start from?
Looking at the btTypedConstraint, I can see that you need to register the constraint inside the bullet codebase (because you need to introduce new element in btTypedConstraintType enum.
Would appreciate any tips on implementing a constraint in bullet in general or any tips on implementing "Point to plane" constraint.
To find out impulse needed to stop the wheel from moving sideways, btRaycastVehicle uses resolveSingleBilateral(src) method.
To apply brakes, the impulse is found through calcRollingFriction (src).
Combining this 2 approaches does not work completely well. Sideways impulse is pretty damn correct and it works good for all 4 wheels, but this calcRollingFriction does not stop the car from slowly rolling from a slope.
Things I tried so far:
1. Using resolveSingleBilateral both for side impulse and for forward impulse. This brings jittering and somehow fails to do the job in the end. It can stop the car eventually, but only on a level ground.
2. Using resolveSingleBilateral in the direction that follows current wheel movement, then projecting the backward impulse on side and front vector of the wheel. This one ended up failing aswel. Then I found out that for some reason, even if you apply the result of resolveSingleBilateral in the direction of movement, the car still keeps rolling off a slope.
Then I got back to good old Kester Maddock's document Vehicle Simulation With Bullet, section Friction Model, and there he describes approach of implementing a constraint for that. Howewer I couldn't make his drafty code working.
Since then I am thinking whether it is possible to use any of bullet's constraints as a base to make a friction constraint. Basically, what I need is a constraint that prevents moving on specific axle, which can be called like "Point to plane" constraint, which must have configurable mixing force (like with 0 it doesn't act at all, and with 1 it stops moving on that axle). Also I need to change that limiting axle with every simulation step, for obvious reasons.
So can someone guide me where to start from?
Looking at the btTypedConstraint, I can see that you need to register the constraint inside the bullet codebase (because you need to introduce new element in btTypedConstraintType enum.
Would appreciate any tips on implementing a constraint in bullet in general or any tips on implementing "Point to plane" constraint.