Custom physic vehicle simulation! Project download included

What is this?

&stc=1

I would say motion blur gone insane x) the wheels spin so fast that the motion blur is weird, especially if you pause the video, plus at that exact moment the wheel had bounced too much on a bump on the terrain. It is why I set a angular velocity on the visual wheels. you can set it to a lower value to reduce this effect.
This is a problem that happens with all vehicles, no matter how I implement them. its only a visual problem, yet if anyone knows how to get rid of it, it would be nice.

@JX53mb So I tried putting this in the advanced vehicle template (migrate, removing the default kart BP, remapping the input etc) and the vehicle gets all crazy as soon as I hit play, the wheels almost detach from the vehicle and it flies away pretty much like the Epic Kart used to/still does sometimes. It works fine on the project you uploaded, any ideas? Untitled.png

@DavidNSilva, the project uses custom trace channels.

Oh…didn’t knew that. I’ll try again now with the custom channels Thanks :slight_smile:

Edit: Now it’s working :slight_smile: Thank so you much @. I must say it’s the most stable vehicle class I’ve tried yet, I’ll probably convert it to c++ and end up using it if the engine vehicles are not fixed.

Try it on a ue4 landscape, I dare you :slight_smile: Just put even a default landscape there, no hills, nothing. It takes 10 seconds to do that so there’s no excuse.

Ohh **** xD okay I take back what I said about landscape, you MUST use a static mesh terrain with complex collision as simple. x)

Were anyone able to get rid of the hitting the curb problem? the front wheels fly away too much when approaching the 50km/h mark as someone previously said. Realistic or not is just too much, I would understand that would happen at very high speeds but at 50km/h climbing a 10cm curb the car should climb on the curb and not bounce around. Imagine if this happened on any of the gta games…it would be crazy. I tried all sort of settings and constraints but to no avail.

I believe that at this point the problem is that the tires do not absorb any of the impact, they are like concrete, I do not know if I can fix that. Still experimenting with it.

I see, I was trying to constrain the rotation /speed of the body mesh and also tried to constrict z speed of the springs but didn’t work well enough. is there some physic setting to resist impact? if there is something like that we could increase it based on speed to stimulate the tire absorption maybe? I tried messing around with the wheels mass but didn’t seem to make a difference.

Imho you need asymmetric dampening and limit on maximum force of the spring.
Why dampeners are important:

Some gritty details on why effect of dampener needs to be asymmetrical

it’s basically to avoid a violent forces from rapid compression of the spring when wheel hits a bump and prevent rapid spring expansion when you drive over the hole in the road.

The higher velocity of the spring the higher dampening force will be, depending on direction of velocity you can set it to 25/75 (this seams to be a typical proportion in regular cars).

thanks for this video :slight_smile: full of valuables informations.

so if we simplify things as much as possible, the harder something hit the wheels, the higher the damping will be, right? so we could make the suspension damping scale up with the vehicle speed. the guy also says that the tire absorb some of the impact as well, wich I could replicate using a sphere trace, and apply velocity to the wheel mesh with collisions disable, to prevent the wheel from getting in the ground. Doing this would simulate tire pressure.

does that seem like a good idea to anyone?

yes I was thinking doing something like that after watching the video, I am not sure about using the hit event however as that is constantly triggered by ground contact. I am thinking getting the z velocity of the spring each frame and then increasing the damping value accordingly, as for the tire pressure it would be simply a constant value added to the damping, the guy in the video even told the tire itself is kinda like a spring and dampener so why not merge the too in our case. however this is all theory I didn’t put any of this to practice yet.

I think this has to be applied on a per spring basis because we can have an impact with the two front wheels and the rear wheels are left untouched,… and we raise the damping for the four wheels things might go wrong.

Hey JX53mb, just wanted to pop in real fast and say thanks for sharing this cool feature with the community. I shared this page with some of our vehicle physics developers and they had some advice about what you had asked me about:

PhysX doesn’t support cylinder sweeps, and currently don’t have plans to add it. However, you could make a cylinder mesh with convex simple collision and sweep that yourself.

If this is a sweep, you could include the components to ignore in the sweep params.

I hope that helps, let me know if you have questions.

BoredEngineer suggested this earlier as well on this thread:

I also recommend tracing/sweeping over constraint setup as you can’t make a fully constraint based car setup like this stable with ue4 (unless your vehicles only travel at slow speeds). I already briefly mentioned constraint setup has issues and I’m sure who’s worked for a while on vehicle physics with physx will agree to the underlying issues.

I’ll list few of the biggest ones here:

  • Constraint based vehicle will be unstable at high speeds since physx can’t solve it properly anymore. You may be able to drive on somewhat leveled ground at high speeds if you just drive a straight line but that’s not what games do.
  • Even without landscapes, your vehicle will not have reliable grip to the ground because on every small bounce on wheel, you loose grip, same thing would happen in real life if you just put full metal wheels to a car. If Physx will provide more reliable way to solve these collisions in the future, this might change but it still wouldn’t still be ideal.
  • You can’t model tire friction properly on constraint only approach. I see you rely on physical materials on this but they were never designed to cover this kind of use case. You can preset one friction value per tire but you can’t modify it at run time on blueprints without swapping the physical materials around. Physical materials don’t make a very believable tire friction even if the contact points kept stable. With tires you’d want this kind of setup: https://pavemaintenance.wikispaces.com/file/view/Figure_2_pavement_friction_vs_tire_slip.jpg/207423378/Figure_2_pavement_friction_vs_tire_slip.jpg. To explain that bit more, your tires usually grip well up to a certain point and then when they lose the traction the force they can put toward the ground drops as tires just slide. You can’t model this properly on physx physical materials and is one reason why you either have grippy tires or car on full drift mode with lower friction value on a physical material. This is especially an issue at high speeds as car just rolls over if you have grippy tires when in reality grip level would go past threshold and start sliding instead, resulting in a just a spin in most of the cases.

Since your car is BP only, the hacks that are done during the Tick (to make it more stable) will be framerate dependent (remember Ticks are run at rendering speed, not at fixed intervals). This means fixes will work differently if player runs game at 20fps or 100fps.

Traced wheels have their own share of issues to solve but most of them are solvable. I admit it’s not as easy approach as just putting together a bunch of colliders with constraints as you actually need to solve the grip and corner cases yourself. But this is also a huge benefit: you actually have control on how the friction gets applied, unlike with pure constraint+collider setup.

Worth mentioning though, you can’t do tracing/sweeping for suspension on BP only project reliably because the already mentioned variation on delta time on Tick, you’ll need to do that during substeps which requires at least some c++ code or a plugin.

Some additional observations on this project:

  • You don’t have antiroll. One reason for cars rolling over in this project is the lack of anti-roll bars, you’ve only setup the COM to the ground level to prevent that but that is more of a hack and will lose it’s effect at higher speeds.
  • The way you do fake wheels is not good for the simulation. You add additional constraint and mass to the simulated wheels physics sim which can make it even more unstable. Your fake wheels are for visuals only, you wouldn’t want to do any form of physics on them. Instead of doing what you do now, you could just disable the physics sim on fake wheels, attach fake wheels to suspension childs without constraints so they’d always follow the suspension. Then rotate the wheels on code, that way you can also control the visible rotations not happening too fast for motion blur.

Your engine sim logic has fundamental flaws in it:

  • You apply more torque at wheels at higher gears, what happens in real life is exactly the opposite.
  • Each gear has it’s own torque curve. Cars only have one engine that works with the same torque curve regardless what gear you use.
  • You force RPM to rise at constant speed (for each gear) regardless if your wheels have grip or not, which means engine sim is totally decoupled from actual cars behavior and it can’t handle wheelspin properly. Do note that in real car, when clutch is gripping, you have fixed connection between engine rpm and wheel rpm through transmission and differential (with manual gearbox).
  • You limit wheels angular velocity directly with engine torque value, I’m guessing this is some attempt to make a traction control but it doesn’t make much sense in the end.
  • The way you’ve implemented engine sim leads to a bug where you can occasionally loose all traction on some bumps and your car just stalls. Since engine sim doesn’t know anything what happens to the wheels grip, it just keeps adding more torque to the wheels which just keep spinning wheels even faster and they can’t grip anymore. When that happens, you have to wait until the cars speed drops low enough for the car to shift down and find a grip again.
  • You control automatic gear changes by vehicle speed regardless what happens on the engine or wheels.
  • Engine setup is based on magic numbers that need to have retuned on each change, even if you change tire friction value.

I must disagree here with you @0lento did you actually tried this project? The only thing that is left unsolved (and it’s a deal breaker) it’s the current suspension problem. The Fake wheels simply exist because the physics wheel spin way too fast, that is the only reason why there is two sets of wheels…the op explained this a couple of times before. The hacks are Not framerate dependent, the hacks use Add Force which is multiplied by deltatime by the engine code. Despite the current suspension problem this is 100x more stable than the default vehicle class ever dreamt to be (even before the 4.14 “fix” )…I can barely drive that for more than 10 seconds without it starting flipping uncontrollably and doing all sort of weird things. I think this project not only is tons more stable but also feels very good…even the vehicle class feels too “arcade” and not like a real vehicle. I would rather use this then the current vehicle class (even before 4.14) anyday. Unfortunaly with the current suspension problem none of the solutions work for me.

Sure, how else could I have given feedback from the projects issues? I’m not here to pick a fight or rain on your parades. Just pointing out what causes issues with this kind of setup.

OP has explained that fake wheels are there to fix the motion blur issue and nothing I said on previous post says otherwise. I did check his project and he does use physics simulation on fake wheels even when he overrides their angular velocity from BPs. They have mass and they are attached to the real wheels so they take part on the actual simulation (they add mass to the suspension and additional constraint to solve) - which isn’t right way to do it. Do note that I told more proper way of doing it too.

You kinda missed my point. Add Force itself handles the deltatime variation (although it’s not perfect but that would be a topic on it’s own), real issue is that if you do quick changes to the physics on each frame. You can only react to the changes only when Tick occurs. A good example of this is if you handle for example suspension on Tick: If game runs 15 fps, you can get new data only 15 times per second vs 100fps you get data in 100 times in a second. With 15fps, if suspension then is fully compressed, you apply full counterforce for the timestep of 66 ms. If the same thing happened at 100fps, timestep would be 10ms and you’d get a new data for the suspensions new position after that 10ms. With 15fps route, you have to wait 66ms just to realize that the suspension you tuned to work properly at 100fps now launched the whole car into space. Similar inaccuracies happen on anything you change on tick that alter the physics simulation, although the effects may not be as serious as on my example.

I think we all can agree that default physx vehicle isn’t very good. Constraint based vehicle on the other hand is a lot worse on certain aspects so it’s not fair to say it’s 100x more stable (as it isn’t). I’ve explained the reasons on my previous post but of course, you don’t have to believe what I’ve written there, it’s just my educated opinion on these matters. For all others, be at least aware of the mentioned issues if you pursue this route.

@0lento Not trying to pick a fight either just peacefully discussing some pros and cons. I understand the point you’re trying to make and I agree that constraint based vehicles are not very good. but implementing a trace based vehicle class from scratch can be very expensive in terms of time and resources. we can easily attach a trailer to this and it works while the vehicle class… well you known. do you know some other readily available solution out there you recommend? Also could you elaborate on what I should expect if I go with this approach? the hitting rough terrain at high speed problem you mentioned did not happen on my tests (and I tried it on mountainous terrain at 180km/h)…of course hitting a 5cm flat curb at 50km/h didn’t went so well lol

There isn’t a solution that’s quick and easy, but that’s how things usually are on gamedev. I’ve been doing this for few years and just sharing here what I’ve found out myself.

Besides the suspension issue, just simply lack of control is one thing that is causing trouble. You can fix friction issue if you just slide 0 friction colliders (wheels) on terrain instead of using physical materials, but then you need to calculate the friction and wheels angular velocities yourself on code and you’d really want to do that at more predictable time steps than what Tick can offer. You’d also want to use additional traces to check the connection to a ground so small bumps will not stop your traction (which leads to the vehicle twitching around, like seen on this project when that happens). This isn’t as simple to do as the pure constraint setup as you’d then need to model all aspects properly, starting from engine. Then again, if one does all that, going to non-constraint setup isn’t that far away anymore.

I didn’t really mean like hills or mountains but things that are uneven and can make small bumps, like the curb you mentioned. Game levels are full of small details. Just try this vehicle on VehicleGame demotrack and you’ll see what I mean. Besides that, constraints don’t work well on physx terrain (ue4 landscape). If you use meshes, you have to use complex as simple and it’ll become pretty expensive quickly. Do also note that even if your CPU can handle it, average players computer might not (unless you test it on a weak CPU yourself). Complex as simple can work if it’s just selected part of the terrain, like roads that don’t have a lot of polygons.

If you carefully prepare your ground plane where you drive this kind of vehicle and don’t go to high speeds, you can make it work. Issues at high speed is not only the bumps on meshes (which you can avoid if you do a really careful level design) but also the lack of control over the friction as mentioned before. And having things out of control is never a good thing on gamedev.

Slightly related to this topic, I recommend anyone working with physics to watch this talk: Designing with Physics: Bend the Physics Engine to Your Will. It doesn’t give all answers to the issues on this thread but it may bring some insight why things happen like they do with physics engines.