Car collisions
Defining the shape of the body for collision purposes. |
|
A car needs to be able to collide. For this, you can define a simple box or a more accurate 3D collision model. Versions before v0.8.3 could only handle an ellipsoid shape for the car vs track collisions, but v0.8.3 (Newton) introduces more accurate bounding shapes.
A car consists of 3D graphics model to visualize the car, but it can have a simpler 3D collision model (simpler because of performance reasons).
You must define a collision box/shape for the car, which is used to
detect collisions with other cars and the track (static & dynamic objects) itself.
You can choose between a 3D model and a simpler box; using the 3D model is highly recommended though. The parameters
are:
- Collision 3D model: this is the preferred way of collision handling using v0.8.3/Newton. A 3D model of the body, much simpler than the real 3D body model for performance reasons, can be loaded to act as the collision convex hull. A convex hull is like pulling an elastic band around your model, resulting in the worst case convex wrapper that just contains all the vertices of the model (this becomes most apparent near the front windows, where a concave corner often is situated). It is recommended to try and round the front and back lower parts of the chassis, to soften situations where the car hits the road surface.
The collision model can be specified in body.model_collide. Don't forget that if you offset the original 3D model (in body.model), you also probably need to offset the collision 3D model.
A good polygon count for the collision model may be around 100-200, but the less polygons are needed, the better the performance will be.
To check the 3D collision model, in v0.8.3 you can enter the script command 'show carbbox' and 'hide carbbox'. With this, you can examine if your collision model matches your expectations.
- Collision box size; body.width,
body.height, body.length indicate the desired bounding box size. Note that for the Newton version of v0.8.3, you are better off also defining a 3D collision model, although to be compatible with older or ODE versions, you should define this box too.
You can get this information from the Modeler's Information button when loading the car's body model. To check
whether you're close to right, you can enable racer.ini's gfx.show_car_bbox to view the bounding box while driving (displayed in wireframe).
The box is automatically sized based on the body's 3D model, unless you enable
your manual settings by setting body.manual_box to 1 (!).
Defining a manual box size is recommended, so you have finer control. Often,
a high body.height value will quickly lead to the car bottoming out (even
more so due to differences of the road's splined representation vs road triangles).
You can optionally move the bounding box around using body.box_offset,
which is also applied if body.manual_box is set to 0. For example, if body.box_offset is "0 1 0", the bounding box will be moved up 1 meter.
Below an example collision is shown (it's the Lamborghini Murcielago, only simplified). Note that the shape will be turned into a convex hull, meaning the 'dents' in the sides of the chassis will be moved outward in the collision engine (picture yourself shrink-wrapping the model).
Collision response is done these days using physics materials (softness parameter).
Testing the collision shape can be done as follows:
- Set racer.ini's gfx.show_car_bbox to 1 to
see the bounding box visually when in Racer. For v0.8.3+ you can also use the script commands 'show carbbox' and 'hide carbbox'. v0.8.3. will also show the 3D collision model if defined (this all only works with Newton).
- Set racer.ini's collision.report_car_track_collision (this setting was called report_car_trk in older versions of Racer) to 1 to
get reports in the console about any car vs track collisions. This helps you
find problems with the car bottoming out. Future Racer versions will include
audio to indicate scratching along the surface. Note that cars bottoming out
can be a real problem; the splines used for tracks can give problems, especially
where big spline patches are used.
More information on creating a full car can be found here.
(last
updated
February 28, 2013
)