Download

Physics Based Truck Game

Hi,

I am trying to make a physics based truck game.

I only have a little experience in 3D modeling with Zmodeler, I used to do mods for GTA IV and Euro Truck Simulator.

The most important thing right now is to get the physics as close to reality as possible. Everything that moves, twists, bends on a real truck needs to do it in my game.

I imported each part of the truck as a static mesh, I created a pawn and I assembled all the parts in UE4 using constraints.



Update

I finally got my truck moving and steering

Also the constraints are much more stable now, almost rock solid

I tweaked the truck to get as close as possible to this one Brass Joe T.S., log truck - YouTube

Next I need to make a proper gearbox and differential



Here are 2 videos showing what I hope to achieve

Hello, Cristineltr.

That looks really good. Rigs of Rods/Spin Tires style, i totally love that. Would you mind sharing some technical details of the implementation? :slight_smile:

I am extremely inexperienced so I might not explain this right.

I started by importing all the parts of my truck, wheels, axels, suspension parts, frame, cabin etc. as static meshes.

After import I double clicked on each static mesh and a window opened where I created collision for it.

I created a pawn, I double clicked on the pawn and a window opened.

I dragged all the parts of the truck in that window and arranged them so that everything was in his place and I checked the Simulate Physics box for each part.

After this I started to add physics constraints and I joined all the parts together.

Thank you,

When I have some time I am going to give this a try.

For the wheels I hope to use Soft Body Physics to simulate realistic tires when this plug-in Tendr: a real-time, volumetric, soft-body physics plug-in for UE4 - Work in Progress - Unreal Engine Forums will be ready.

Good luck to you. Hope you will make nice game.

Thank you for the reply :slight_smile: Wheels look really stable, never happened to achieve this by myself…
Mind sharing how you made the suspension? Couldn’t get constraint to behave as a spring…

Here is a picture with my suspension constrains

73709cd83bbbed78bf99a1e1184f70d40a060a06.jpeg

To make the wheels and the axles more stable I had to increase their mass a lot.

As you can see in the video below they are not 100% stable you can see the rear axle moving when I go over that box at the beginning

From what I understand this is a problem with PhysX: http://forum.unity3d.com/threads/ape-advanced-physics-engine-for-robust-joints-and-powerful-motors.259889/

Looks great!
How does it behave at high speed?

I did a similar setup for 10 wheeled truck and wheels kept going crazy at high speeds. The only thing that would make them stable is to completely remove their friction. I’ve decided to simulate friction myself but run into a problem of not being able to calculate wheel load because of this bug:

So I’ve ended up with simulating suspension manually as well.

What kind of collision mesh you use for wheels?

More specifically the problem is that friction is applied to wheel and then propagates through chain of your constraints to the main body. For this to work correctly you need to scale the mass of connected objects in such a way that it’s as close to 1:1 ratio as possible. One way is to fiddle not with mass but with ‘mass scale’ property. Unfortunately this leads to a setup where 30 ton truck has a 3 ton suspension axles connected to 3 ton wheels.

At high speeds the wheels jump like crazy but I hope to use Soft Body Physics to simulate realistic tires when this plug-in Tendr: a real-time, volumetric, soft-body physics plug-in for UE4 - Work in Progress - Unreal Engine Forums will be ready, so for the moment I don’t try to make very high poly collisions for the wheels.

Some sort of tutorial on this sort of thing would be super cool. :smiley:

Duncan, there was a project you could download. which had the basics of this, but now it can’t be downloaded. this was the forum page. I downloaded it months back and learn’t how it was done, thanks to the publisher Polyplant all the credit for the tutorial project is to him. I have just uploaded the rar file to my mediafire account so you and others can download it. Also this project is for engine version 4.7

Thanks Sean. :smiley: I remember reading that thread after the first post what it is now (nothing but pictures) so I was a bit confused as to what was going on. I will be downloading that sometime tomorrow, thank you. :slight_smile:

Update

I finally got my truck moving and steering

Also the constraints are much more stable now, almost rock solid

I tweaked the truck to get as close as possible to this one https://www.youtube.com/watch?v=jidbxiZc5g4&feature=youtu.be&t=39s

Next I need to make a proper gearbox and differential

Very nice! I like how most of the parts are connected to each other instead of being single solid body. The wheels are turning a little to fast, are you using SetAngularTarget of constraint for steering?
Btw, any tips on getting more stable constraints? From my last experiment with aerosled I got much more stable behavior by adding sockets and adding them to physics constrain parameters.

All the blueprints that I made were made from watching this 3 Videos Custom Vehicles in Unreal Engine - 2 - Simple Car Using Physics Constraints - YouTube Custom Vehicles in UE4 - 3 - Add A Torque Curve & RPM To Simple Car so it can accelerate - YouTube Custom Physics Vehicles in UE4 - 4 - Setup Rear Suspension On Simple Car - YouTube

I didn’t know how to do any blueprints

Here is how my steering blueprints look like

b5accceca1fec278cbdc1c68be7efe7637e15721.jpeg

For the constraint stability one of the most important things were this settings on all the truck parts

513fd8263612824a9a348a51116780a7ed0906af.jpeg

And the Constraint Projection Values are set to 0.1 for the Projection Linear Tolerance and 1.0 for Projection Angular Tolerance

Another very important thing is Sub-Stepping. I set 16 steps and Max SubStep Delta Time to 0.016

Initially the Max SubStep Delta Time was set to **0.016667 **which was perfect at 120 FPS but when I dropped the frame rate to **60 FPS **the wheels were getting pushed into the ground and jumping around this problem got fixed by changing the Max SubStep Delta Time to 0.016

2511f697a840b96683d67aa56602e7741921e164.jpeg

Interesting, I’ve never tried fiddling with “Should Update Physics Volume” and setting under CCD. Will give it a try.

At first my steering setup was similar to yours, for steering this thing:

But now I’ve changed it a bit. When you enable “limited” on angular constraint, you can call “SetAngularTarget” in degrees for it. The nice thing is that you can change this target in real-time, so when I want to turn right I simply start to slowly increase target yaw degrees and constraint will just hold it in that position. I’ll post screenshot of blueprint when I get home, or you can grab a project from github repo GitHub - BoredEngineer/UE4_Tracked_Vehicles: Custom tracked vehicles for UE4, NOT based on PhysX Vehic, blueprint is called Aerosled.

These are really cool tutorials! Thank you for the link.

This is how code looks like:
ee80c9da7827f7456a1077b578cd26e144869fec.png

ProcessSteering() function is called on every Tick event.

Setting on constraints are like this:
https://www.dropbox.com/s/tzfxs0f96ez43g0/ConstraintAngularTargetSteering_Settings.PNG

Thanks, BoredEngineer

I also have a very strange problem when I drive on a diagonal on the map my FPS drops to 1 FPS
I made a picture

The green is the directions where everything is ok no mater the speed and the red is where is the problem

b21f9d15e5d563c820e834274250293906a868c0.jpeg

I’ve never seen such bug before. My guess is that you have a problem with one of the physics settings like “UpdatePhysicsVolume” where it needs to keep recalculating some sort of bounding box, when you drive straight along one of the axis then bounding box keeps it shape. This is just a guess.
Do you have any other blueprint code there except for the steering?