Little demo of my work-in-progress ray and convex cast vehicle [download].
My method works for any number of contacts per tire (the available force and load is divided by them) and I've implemented three types of tire contact sources (where the tire meets the ground and other objects):
1. simple raycast - casts 3 rays under the car, divided on the width of the tire.
2. circular raycast - casts 3 rays horizontally and 8 circular around the tire, green lines (so not only collisions from under the tire are found)
3. convex cast - casts cylinder the size of the tire towards under the car, finds all contacts with the ground
Convex-cast only works for objects under the car, so I'm considering trying finding bodies near the tire and finding the constants using collision-collide.
Everything is pluggable (models for tire, spring, damper, visualizers, contact sources etc). I've implemented pacejka tire model (combining of forces is not complete).
For every contact, I have found/calculated the following:
- positions of tire contacts with the ground
- penetration
- load force
- lateran and longitudunal directions
- lateral and longitudinal forces
- lateral and longitudinal velocities
- max lateral force
- max longitudinal force
- current roll
- slip angle
- slip ratio
- camber
Right now, every contact forces are applied by a different joint object between the frame and NULL that are recreated every time tire becomes airborne-touches the ground again and when rolling on a new body, but I'm considering one joint per tire. Is there any limit to the amount of linear rows I can add in one joint?
I tried creating the joints between the frame and the body that the tire is on, but NGD went crazy for some reason. This would be good so for example when braking on a moving not-too-heavy body, the body would start slipping on the ground, same with lateral and longitudinal forces.
An UML diagram of current setup:
Most important buttons for the demo:
- arrows to move around
- hold left shift to use more power to accelerate and also to brake
- F1 to toggle displaying debug graphics
- F2 to toggle physics pause
- F5 to toggle car chase mode
- F8 to toggle contact source (convex-cast, circular ray-cast, simple ray-cast)
- F9 to hide debug arrows of the car
- END to toggle car reverse
- hold left ctrl to pick objects with mouse