# GTA2 type driving phsics

Hey guys,

Iam trying to implement a top-down-viewed driving model as we know it from GTA2. The handling felt very arcadelike but kind of made a lof of fun.
Iam working entirely with blueprints so far, due to my lack of C++ skills. What I did is taking my car mesh and, by taking the keyboard inputs for “forward and backward” increasing and decreasing the RPM of my “engine” and shifting through three gears (as it was in the original GTA2, if I got it correctly). Then the current RPM value is used for calculating the force that I apply to the car in direction of its forward vector (taking an additional multiplier for higher gears; the higher gears, however, reach high RPM slower).
Steering works by simply adding a local rotation to the car and I even got it implemented that the car kind of sticks to the driving lanes.

So far everything works nicely… However I reeeeally struggle with the car on the streets itself: In the first attempt I followed a tutorial and included four “hover-components”-blueprints at the position of the wheels that, if in sufficient proximity, add force in vertical direction and, thus, let the car hover over the street. Although that basically works I could not get it in a way that the car is NOT strangely shaking or tilting or whatsoever.

Then I thought that I can maybe follow an acutally easier approach: I removed the hover-components and just to a line trace from the car downwards to get the distance to the street. Then I use the “AddWorldOffset” and just offset the mesh to a fixed height and, consequently, I can stop the car from tilting around by setting its world rotation (x, y values, z is not impacted as that reflects the steering angle) to match the orientation of the street below.
This gives me a nicely stable hovering car mesh but messes up the entire “Add force according to RPM” model I implemented before. It is just weird, all values (rpm and forces) are correctly calculated but not properly applied. The car barely moves unless a change in the gears is triggered -> then the thing kind of explodes and flings my car through the entire map. I cannot figure out what is the connection there, because no force should be applied at all, if the car is changing gears…

Is there, by any chance, something weird going on when I combine the use of “not phyisically correct” AddWorldOffset nodes for setting the car position and then applying Forces through the SimulatePhysics-system??
Do I probably have to go back to my HoverComponents? If yes, any ideas of how to get the car in a stable hover state??

Or do you have any other ideas on how to realize a GTA2-style driving system?

Thanks in advance and best wishes,

PS: If wished, I can upload screenshots of the BPs!

Any hints, someone?

The rule of thumb is to use only AddForce/AddTorque/AddImpulse when you work with physics simulated objects. Direct manipulation of position (AddWorldOffset) or velocity can lead to unexpected behavior as you manually changing variables which should be handled by physics. If you choose to directly manipulate position/velocity then your object needs to be kinematic.
If car is shaking with hover component, it means either force is too large or damping is too large, which component are you using? I don’t remember such standard component.

No, the HoverComponent is not a standardContent-Blueprint. I’ll show a screenshot later this evening or tomorrow. I guess I have to optimize that in order to come to the desired driving behavior!

I’d personally go back to using the hover components, and to stop the shaking you’re experiencing, Damping!
You could just use the rigid bodies Linear / Angular Damping,
but more better results, you’ll need to calculate the damping for each hover component using Hooke’s Law for damped harmonic motion

F = -kx - bv

Where;
F = Spring Force
k = spring constant
x = spring displacement
b = damping factor
v = relative velocity of start and end points of the spring

OK, so Iam going to go back to the HoverComponent By tha way, that is how I set it up: [Unreal Engine 4.7+] Hover Vehicle Blueprint Tutorial - YouTube
If I understand you correctly I have to calculate the damping factor b at each frame again according to b = -(F+kx)/v ? Hmm, have to think about it…

Another thing that is troubling me: Is it actually smart to use four HoverComponents at the position of each wheel? Or is it for my purposes of just having a smoothly driving car more reasonable to take just one in the center of the CarMesh? Iam not sure how accurately the engine takes into account the distribution of mass within the car mesh, but if it only takes the bound size and assumes homogeneous mass distribution and if the HoverComponent is in the very center then it should work as well?

Or to follow a completely different approach: Is it possible to reduce the friction below the CarMesh? So that I do not need any hovering at all but have the car literally slide over the streets?

I see now, yes spring of that hover component is missing damping which is very important. Damping removes oscillations of the spring and overall influence stability of the system.
I have a couple of different springs in this project: [OPEN-SOURCE] Machinery Modelling Toolkit - Community Content, Tools and Tutorials - Unreal Engine Forums
but to save hassle, this is a screenshot of one of them:

The bottom part (where it says “25% damping if spring is compressed and 75% if expanding”) is what makes dampener asymmetric as in real cars. You can replace it with just multiplication by 1 for simplicity.

Regarding some of the parameters:
Spring Length” is a length on previous frame and “New Spring Length” is what you’ve measured in current frame. This is used to calculate velocity of spring compression to calculate damping. At the end of each frame, after you are done with calculating spring force, just do Spring_Length = New_Spring_Length
Damping Desired Velocity” - just leave it at 0.
Spring Stiffness” - is a scale of the force that should be produced by suspension. Normally this value is quite large. Basic idea is let’s say your want your suspension to produce enough force to hold full weight of the vehicle at half of suspension compression. As compression goes from 0 to 1, at 0 compression we have 0 force and at 1 compression we have full value of “Spring Stiffness”.
Let’s say we have 4 wheels (4 suspension blocks) and vehicle mass is 2000kg. The minimal force we need to fight gravity would be VehicleMass * AccelerationByGravity / NumberOfWheels
MinSpringForce = 2000 * 980 / 4 = 490000
But we get this value only at 100% compression and we need it at 50% of compression so just multiply it by 2 and that would be your SpringStiffness.
Damping Coefficient” - usually is about 1/100th - 1/10000th of the Spring Stiffness. You have to tune it for specific spring force/vehicle mass. Start with 0 and start raising by few thousands until you don’t see any oscillations of the spring - vehicle’s suspension settles as fast as desired.
If you see your vehicle shaking then either spring is too strong and springs on opposite sides are fighting each other, or dampener is so large that it prevents spring from producing enough force to do useful work.

There are other ways how to make spring, it really depends on what would work the best:

Regarding if you should use a single spring for a whole vehicle or one for each wheel - this is really depends on what you want to achieve. 4 springs take more performance and require more tuning but they add ability for your vehicle to react timely to changes of landscape and rolling of the chassis when you enter turns or accelerate/decelerate. Engine does consider homogeneous material but shape your collision mesh will still have quite a large effect on how vehicle reacts to various accelerations, angular is effected by this the most.

To make your vehicle slide, make a custom physics material with very low friction (0.0 - 0.01) and assign it to mesh. Just google UE4 physics material tutorial for an example.

Thanks a lot for the screenshot. I found the time to implement that yesterday evening and it seems to work nicely
Now the car lies smoothly on the street. I just need to optimize a bit more all forces^^

Hey guys,

Iam back at that topic, because I could not really get the desired results and doubt my strategy…
What I want to achieve is probably most easily to see in a video YOUTUBE-VIDEO. Or, just download the game and give it a try, it is doubtlessly extremely funny

What approach would you guys choose to obtain that kind of handling? I need a car that lies flat on the street but can still jump and interact with physical objects. The entire driving-physics is extremely arcade-like.
With my approach I could get the cars driving relatively nice but with the hovering I never get the friction that I need… Iam currently trying not to use the hovering but having the car mesh lying directly on the street, which gives nice friction but makes me use very high forces to move it anyways…
Or would you try to go with the built in wheeled-vehicle and tune it to get that kind of behavior??

I would be extremely thankful for any thoughts or ideas on that!

Is your game top down too? 3d or 2d

It is in the top-down perspective as well.
Basically I want to have the gameplay of the GTA2-Multiplayer remaked in UE4 (different graphics setting though).

Alright I get it,
I threw some stuff together and made a simple project for you to check out, hopefully you can find something useful in it

It uses a frictionless vehicle (cube)
and I apply the lateral (grip), longitudinal (rolling resistance/throttle/braking) forces manually
It comes from a vehicle project I was working on before, hence the suspension components, but there’s no suspension in this project, I’m just using them for the grip

Wow, this is extremely cool, thank you for your effort!
Can’t check it out until tomorrow evening, unfortunately, but Iam very curious to see how you put together everything.

Sooo, sorry for the late reply, but I finally found the time to have a look and give it a try.
First of all, the way the cars behaves in your example project is pretty close to what I want to have, so very well done

I reproduced the blueprints essentially 1:1 into my project and cannot see any difference anymore, however my car does not feel the same. It appears wayyy to light (although I used the same mass of 2000 kg whilst having the same force values that you used) and is getting flipped over easily. Any ideas why that is happening?
And, in your throttle-blueprint you use an expression that takes the location of the actor and subtract its up-vector times a factor of 65 to specify where to apply the force. Does that basically do the same as when I set the CenterOfMass of my car-mesh to be 65 cm below the floor?