Project Overview

My final project is a dynamic simulation of a wheeled vehicle with suspensions, based on the cloth lab. The vehicle is entirely physics-driven and moved through forces exerted by the suspension springs as well as drive forces along the wheel vectors for user control. As a result, phenomena like vehicle weight transfer during acceleration and turning can be seen here.

Vehicle Body

The body of the vehicle is made up of a lattice of particles connected by springs - a 3D version of the cloth lab. Simulating the body as a spring lattice allows for it to naturally handle the torque from the drive forces acting on the wheels. Each particle in the body is connected to its six direct neighbors, as well as its twelve diagonals for shear springs, and six neighbor's neighbors for bending springs.

Suspension

The suspension springs are handled separately - each wheel is treated as a particle connected to another on the vehicle body (the suspension's endpoints). The wheel position, however, is not affected by the suspension forces and is determined by a line trace outwards along the suspension direction to the first collidable. The suspension rest length is also the max distance of the line trace. If no collidables are within that range the wheel is positioned at the rest length. Otherwise, the wheel is positioned with its edge at the intersection point and the retracted length is used to calculate the spring force on the vehicle body.

Wheels

The wheel meshes are drawn according to the position determined by the suspension line traces, and have a theta rotation to turn them left and right. The drive forces are applied along the forward vector of the wheel. The phi rotation simulates spinning of the wheel and is calculated based on the wheel radius and linear velocity along its forward vector.

Demonstration

Download

Source Code

Running

Make sure environment variables for GLM, GLFW, GLEW, and Eigen are set up. Then, if on Mac or Linux, just run the run.sh file in the build directory. Otherwise, follow the usual setup instructions for Windows.

If the simulation is running too slow or too fast, try adjusting the n and h values in Scene.cpp.
n (line 47) controls how many particles per side are in the box - a higher value slows down the sim and lower value speeds it up.
h (line 33) controls the time step - a higher value speeds up the sim and lower value slows it down.

Controls

Space: play/pause
H: step one frame
V: toggle spring visibility
B: toggle body visibility

W: drive forward
S: drive backwards
A: turn front wheels left
D: turn front wheels right
Q: turn all un-turned wheels left (you can use A/D and E/Q at the same time)
E: turn all un-turned wheels right

R: resets car back to original position and attitude
Shift: multiplies drive force by 5x
Left Ctrl: multiplies drive force by 0.25x
Esc: closes the simulation

Issues and Areas to Improve

The line trace method for wheel positioning works well for gradually-sloped surfaces like a sphere, cylinder, or low-angle plane, but teleportation results when driving onto boxes or onto a raised plane (like from the side). One way to resolve this would be to give each wheel a collision capsule.

Currently, no friction is implemented. There is an overall damping factor that is providing a similar effect that prevents drifting, but also slows you down midair and sometimes acts noticeably different than friction, especially when rolling down a slope. A proper friction implementation would increase realism and allow for factoring in tire grip and weight distribution on the actual applied drive force, which is important for slopes and wet surfaces. Implementing lateral friction would also prevent sliding down slopes at certain angles and allow for turning the car when it is moving without applying drive force.

Collision would need to be fleshed out more, currently it's a very simple implementation for line-sphere and line-plane intersections. A collision library may be useful.

For visuals, mapping a mesh onto the particle lattice would be nice - vertice positions can be interpolated based on the particle positions.

Deformation of the vehicle body from collisions should be pretty simple to implement since it's already a spring lattice.

Dr. Sueda also mentioned that using a texture for the ground grid instead of lines will resolve the aliasing effect in the distance.