Wheeled Vehicle Sim - Study 4
A study in making wheeled vehicle setups in UE4 with a focus on realistic interactions with the world and other objects
A couple months ago when this whole Covid situation unfolded I figured it was a good time to stay indoors and bust out a one week study about physically accurate wheeled vehicles in Unreal Engine 4. So a mere quarter of a year later, here’s the post! It’ll be a lightweight post for now, with maybe some more technical posts following it up.
I have made it sort of a hobby to create realtime physical vehicle systems, and I make a point out of creating them from scratch every time, so that I might find some new and interesting way of solving problems. Tanks, planes, hover vehicles and ships I’ve touched on before but never really wheeled vehicles and so I figured it was about time. As you can see the truck model itself is far from finished, but I figured it was finished enough that I could make it work like a truck, and so I set myself some goals for the week.
- Create a physically based wheeled vehicle system
- See if I could avoid the need for substepping
- Make it AI friendly from the get-geo
- Implement wheels, differentials, gearbox and engine in a modular fashion
First of all, although I have used many sources on this project and similar ones, a big shout out goes to Ivan Novozhilov on youtube, since even though he does his videos in russian I have learned so much about realtime vehicle physics from his countless hours of content, courtesy of automatic captions.
Creating a physically based system
The critical part of this is making sure there is coherency and consistency when it comes to the units used. Like the springs have a certain amount of force they can excert, which combined with the weight of the vehicle over each wheel decides the friction between wheel and the ground, and that friction in turn and in combination with the engine power decides how much the wheel will be able to accelerate the vehicle. This means that I can load my truck with cargo and its springs and handling will respond accordingly without me having to implement any specific behaviour. Most of this I’ve tried to learn through reading about physics, but here Ivan has been a big help.
Trying to avoid need for substepping
Previously I’ve fixed the issue of low framerate instability by implementing substepping for the vehicle physics, but I wanted to see if I could avoid it as it does feel like a cheap fix. Although I did manage to improve it compared to previous designs, it is still quite shaky at low framerates. However it doesn’t just implode and try to escape the planet like some of my previous attempts!
Making it AI friendly from the get-go
The simple solution to this is just to make sure you properly expose limited controls on the pawn like turning and throttle and little else, and then put all your player input code in a regular controller and then AI code in an AI Controller. This way, from the moment I had a basic AI set up, no changes to the truck would break the AI any more than it would break it for the player. So I made a path following AI that I could use to test my truck setup in various situations all at the same time!
Modular implementation of parts
I wasn’t quite able to get to where I wanted with this. Even though I have all these vehicle components like wheels, engine, gearbox, differential etc. modularized and somewhat working, when it comes to making them all communicate without inducing a feedback loop is tricky, especially with things like the differential and reactive forces on the engine. I know integration will play an integral (hah) part in solving this but for now I wasn’t able to get it to where I wanted.
Final look at the end of the week
Maybe next time I’ll have the model finished!