Home / Xpresso / Xpresso Anonymous / Car suspension


Car suspension

In this tutorial we will create a suspension for a car. The goal is to control a wheel so it remains firmly on the ground as long as the suspension allows.
The basic idea is to detect where between the lower end and the upper end of the suspension range the wheel makes contact with the surface. The Ray Collision node is especialy usefull for this. One Null is used as the main suspension with two Nulls as children, representing the upper and lower end of the suspension range. These two Nulls are the points we are using for the ray collision node.
Ray Collision will cast a ray (draw a line) between those points and the first intersection with a given polygon object is noted. The node will give us the event (Bool) as well as the global position where the collision happened.
Since we want the suspension to work in relation to the car body we will have to do the calculations for the suspension in local coordinates, otherwise the wheel would move along the global y-axis not the cars y-axis. To make this easy i have included two COFFEE nodes that allow for easy conversion from local to global position and vice versa. (info)
To make control easier we are using User Data fields on the suspension Nulls to define the suspension range as well as the wheel radius. The collision object and the wheel are assigned via Link field properties of the Xpresso node (info)
Beside the suspension control there is a small Xpression on every suspension range Null that will position it correctly according to the settings in the suspension Null.

To make the Xpression easily transferable all references are either relative (suspension range Nulls/Ray points) or made by link fields.
To make the suspension work correctly we have to differentiate between two states depending on if there a collision got detected. If the collision occurs it's global postion is translated into local coordinates relative to the suspension and the wheel Radius is added to it's local Y value. The new local position is then translated back to global coordinates and assigned to the wheel. If the Collision does not occur the local Y position of the lower Ray Point is used (completely extended suspension). You will find additional comments in the Xpresso setup. scene movie

Back to Xpresso Anonymous