This video by Toyful Games does an amazing job breaking down the physics and how to simulate it:
Best of all you can play it in their game, Very Very Valet for Nintendo Switch
This video by Toyful Games does an amazing job breaking down the physics and how to simulate it:
Best of all you can play it in their game, Very Very Valet for Nintendo Switch
Just watched it, it was beyond amazing. Not just a good introduction to car physics, but to a lot of basic concepts like springs, friction and acceleration.
Highly recommended, thanks Kurt!
Absolutely! What a great introduction to what is the absolute essentials to simulate car physics. Even realistic car physics begin with very similar basis.
However, in my opinion there’s a flaw with the description of the suspension that may lead to misunderstandings. The description of the spring (minute 5:00) says that the spring can be stretched and that produces a force in the opposite direction. Then it states that the “offset” must be signed. While this is true for springs, it is not for car suspensions. The video leads to the erroneous conclusion of that a negative force must be applied to the car’s rigidbody. In actual car physics this doesn’t apply: if the suspension spring happens to get stretched somehow, then that wheel is in the air and that suspension doesn’t apply any force to the rigidbody.
Also, the video doesn’t state any maximum distance for the raycast. If the maximum distance is the rest position of the spring, then it will be mostly ok and in line with actual car physics. If it’s beyond it will apply negative forces to the rigidbody, which is pure arcade car physics. If there’s no maximum distance (infinity) then the car will never jump or leave the ground.
Don’t get me wrong, the video is awesome describing a simulation model intended for arcade vehicles. Applying negative suspension forces is a perfectly valid trick to improve the stability, and the gameplay (i.e. how easy/hard the vehicle can roll over or jump) can be fine tuned easily. However, I think it’s important to mention this aspect.
I saw that too!!! But I played with it a bunch and basically what I ended up with this this for my suspension:
namespace ArcadeCar
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class CarSuspensionParams : ScriptableObject
{
public float SuspensionFullDistance;
public float SuspensionRestDistance;
public float SuspensionSpring;
public float SuspensionDamping;
void Reset()
{
SuspensionFullDistance = 1.0f; // <--- full raycast (maxDistance:)
SuspensionRestDistance = 0.7f; // <--- what we consider zero
SuspensionSpring = 1.0f; // <- scaled to mass of car
SuspensionDamping = 0.5f; // <- scaled to mass of car
}
}
}
And with the computation, as you point out, when the “spring” is beyond length, yes, it does compute a negative P term, which makes the wheel sort of like “glue” and pulling down on the car at that point.
This is NOT how real physics works but you know what? It is very subtle but actually helps the car feel a bit more solid and stuck to the road!!
Anyway, when I’m finished fiddling with this I’m putting it all out on a github repo, but I didn’t get that done over the weekend, so it might need to wait until next weekend.
Exactly! In the end, this model is for gameplay and doing so is a perfectly valid technique to improve stability. Or, more importantly, a stability that can be configured easily.
My concern is that watching the video can lead one to believe that car suspensions work in that manner, which is incorrect.
Hey!
I Am Very New TO Unity And I Have No Idea Of How To Implement This Physics In A Unity Project
Any Help From You Guys Can Teach Me ALot
Welcome. Be sure to read forum rules. Do NOT necro-post to old threads.
Sounds like you need to get busy with Youtube tutorials… LOTS of them. Here’s how:
Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:
How to do tutorials properly, two (2) simple steps to success:
Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!
If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.
Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.
Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.
Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.
Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
Finally, when you have errors, don’t post here… just go fix your errors! Here’s how:
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
Imphenzia: How Did I Learn To Make Games:
Since the thread was necroposted anyway, I played with the concept in that video, but must’ve done something wrong with my implementation of the slip forces. Even though all four springs were oriented in the same direction, I always end up with a runaway torque buildup on the body and the body starts spinning and drifting away. The video doesn’t really cover yaw torque at all.
Can you write down your github link to your this car physics project?
One of the most significant issues I’ve been trying to solve is how to imitate static friction. No matter what I do, I can’t seem to eliminate sliding on sloped surfaces like the native wheel collider can do.
Any pointers or help on this matter would be greatly appreciated.
Thank you.
Get the velocity of the car and the normal of the surface it is sitting on. Project the velocity vector onto the surface normal, and subtract the result from the original velocity. This gets you the velocity on the direction tangential to the surface.
If this velocity is below a threshold, just apply an acceleration in the opposite direction (same magnitude). This has the effect of zeroing out any velocity along the surface below the threshold, which should get you a pretty good approximation of static friction.