🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Arcade car physics

Started by
23 comments, last by bmarci 5 years, 7 months ago

I would like to make a kind of Mario Kart (a little different though, but the base would be great) and therefore I'm trying to acquire the background required to implement that in Unity.

I've seen this video mentioned in many places and it's indeed very interesting, so I went on and tried to implement it myself.

First, with the car suspensions. The guy doesn't mention the damper (a notion that I haven't quite grasped yet btw), he just talks about applying a force relative to the suspension compression. Is there any way it could work this way, or has he just forgot to mention it? By implementing it without damping my car will "wobble" when on the ground, but then I don't know what constants I should use for the spring.

Cheers :)

Advertisement

Yeah, that video is pretty awesome, I fudged my way into a similar solution a few months ago.  When he was saying the devil is in the details and that it takes a lot of tuning, that's exactly what he was talking about.  It took me a few weeks solid to get a similar game mechanic in Unity to work(was my first time working with physics like that).  And I don't think I watched that video first. ;)  It can work but you pretty much have to find all of those values for yourself, expose all of them that you can in the editor and just start playing with different values until they start behaving.  If it's just wobbling when it's not moving, you could always turn some of the physics forces off when at rest. 

Make sure you are applying the correct types of force, i.e. https://docs.unity3d.com/ScriptReference/ForceMode.html  They are each very different, and sometimes they operate differently than you might think they will, unless you really have it down.  Experiment with them.

I can say that starting small helps, only apply one force at a time(or group of them 4 corners/etc.) and only apply the minimal force you need to achieve the desired effect.  Then add another force(or counter force) and tune it, then re-tune the first force because they will probably effect each other.  Then when both of those are working perfectly, add another, and tune all 3 to work together.. etc.. etc..   It can be a little tedious.  But worth it. ;)

Hope it helps, if you get stuck with some specific code, feel free to post it up.  Lots of smart folks around here.

*Damper: The way I think about damper is that you're restricting the speed at which something can move or "bounce". 

If you are trying to dampen a force, then you have to apply an opposite force that is a certain amount LESS than the force it is attempting to counter or (dampen).

Oh yeah, you can also create some nice dampening effects by modifying the rigidbody drag values. ;)

Thank you for your kind comment Septopus :) Glad to see someone tried that too :)

Yes that's what I'm intending to do, I like the self-taught process here. I have one specific question for now, it's "does it make any sense to implement a spring (suspension) the way he mentions? That is, only with a force proportional to the compression ratio of the suspension.". I've been toying a few days without it and the result is nowhere near satisfying. So I'm just wondering if that could even lead anywhere.

If that's the effect you are going for, yeah, this is about the only way to do it that I know of. 

I think even the standard assets vehicle controller uses the same methodology, it's almost impossible to use out of the box though because it has TONS of fairly obscure variables.

Hmm sorry for double-checking, but that "only way" means that having just a force that pushes the vehicle back upwards depending on the current compression ratio (== distance from the bottom of the vehicle to the ground) is enough?

The standard unity assets use damping, among tons of things. But I don't truly understand this concept, only the formula.

You'll probably have to dampen it or try some different force modes, I'm sure the physics are a bit differently controlled between ue4 and Unity.  I ended up scrapping my pure physics approach(which worked fine) due to game environment complications, so I can only really speak from memory.  I believe I ended up scaling the forces independently based on individual distance to the ground, with a rapid fall off to equilibrium at the desired ride height.  Matched by a downward force that kicked in rapidly when the corner height exceeded a threshhold(I was trying to avoid flipping completely)....  Also, make sure you are setting a reasonable value for your rigidbody mass!  This makes a huge difference in how the force modes misbehave. ;)

*fall off to equilibrium, not zero.  If the force goes to zero you will hop...  Which might be part of your "wobble"..  

** I was also building for dynamic load capacity..  The vehicle could carry other rigidbodies and the suspension adjusted automatically.  May be overkill for you though. ;)

Another thing you can try is applying forces based on velocity, specifically dampening forces.  Iirc, my dampening system was modified or triggered by point velocity checks.  So if a corner's upwards velocity was over a threshold then the dampening would increase...etc..

Thanks for the comments :) Sorry for the lack of reply, I'm actually working towards it, learning every bit one after the other. So far I've spent the last few days on the springs. I thought I had got it alright, but there's a problem with slopes where the simulation sometimes blows, and it doesn't even support stiff suspensions (k > 150) without oscillating badly, so I'm back at it :)

In the meantime I've got the acceleration and braking working the way he describes in his video. It feels awesome, because no standard car simulation gets anywhere close to that :x

A little demo of what I have so far :)

It's all coming up so nicely. I feel like a student again haha, trying many things until I just get it right (and leave no room for something fishy or not figured out).

I'm not completely blocked for now. I'll add the downforce (starting with a simple force parallel to the normal to the ground surface below the car, multiplied by the velocity of the car in its local coordinate system), then friction (so that I can push the engine much further, as it's currently almost free-wheel, and it can fight gravity better, allowing for fun, arcade slopes) and change the shape of the car collider obviously (sphere?).

Will keep you posted :) thinking about starting a project topic btw, if you have something for that? :)

CarGame-v1.mp4
On 11/6/2018 at 6:04 PM, Septopus said:

Another thing you can try is applying forces based on velocity, specifically dampening forces.  Iirc, my dampening system was modified or triggered by point velocity checks.  So if a corner's upwards velocity was over a threshold then the dampening would increase...etc..

Yup exactly! Thinking about doing exactly that. Like him I have a target suspension compression of 0.75 (well in my system it means the opposite of him, where 1 is fully extended and 0 compressed), so I'm thinking about increasing the damping a lot when we reach 0.25, this way the car body will never actually hit the ground. This is one of the things that are so easy to do when you do it your own way: I believe Crash Team Racing didn't even check for collisions on the bottom of the body, only simple sideways checks, and then restituting the same equivalent force to both bodies so that they split quickly, and for walls it's likely the same as they do in most FPS (one thing that I haven't grasped at all yet).

This topic is closed to new replies.

Advertisement