This is an updated simple tutorial on creating a fully driveable physics vehicle in Unity 5.xx using no WheelColliders. The script and car setup are optimized for mobile platforms like iOS and Android. The vehicle uses no other physics objects other than a single box collider containing a rigidbody. The script also determines runtime platform and uses inputs for PC/Mac on those platforms and switches automatically to touch input if on an Android or iPhone device (it’s a cross platform vehicle). If you’d like to save time copying/writing the script, acquire the scene, prefab, scripts, 3D model, shader and textures please visit the link below and donate $10 bucks. If not, this tutorial is totally doable without acquiring anything! You’ll only need your own 3D vehicle model and some time to write the script.
Is this actually usable on anything other than a plane?
I’m pretty sure that in most scenarios you’ll be either going over terrain with slight slopes and obstacles on it or a bumpy terrain.
And you don’t even show how you would handle hitting a wall.
From the short demo I can see that your car doesn’t swing left or right when you turn, so I suppose it literally can’t rotate any other way expect on the Y-axis.
This is literally a box that you move move in X and Z direction and rotate it’s Y-axis, isn’t it?
Just checked your portfolio, looks like you are an artist, that explains why you think this little script you’ve made is something worthy showing other people and even asking money for it.
It might look good to you since you’re not into this line of work, but I can assure you that this is anything except an actual vehicle physics asset.
Trust me you’d be much better off looking up edy’s vehicle physics on the asset store. It will save you a lot of time for figuring out how actual vehicle physics work (there is a lot of math involved), I can guarantee to you it’s quality.
Thanks for the input. It’s a free tutorial. People can just watch the setup and copy the code by writing it if they need something like this. I only offered the paid aspect if they felt like they wanted the FBX model, the car paint shader with mask and such. You are right, this is a box that slides around and rotates on the Y axis. It is nothing like Edy’s physics or any kind of realistic simulation style vehicle physics. It doesn’t handle extreme elevation changes well, no, but gradual ones yes it handles them just fine. It’s ideally suited to flat style tracks and or city roads with gradual elevation and or slope changes. It can handle jumps as well, and I have other tutorials that can show how to stabilize the car in air after a jump. You pretty much explained it, but I like to explain this as an ice cube being slid around by being pushed. That’s exactly what it is, nothing like simulation, nothing realistic, but fully functional as a simple vehicle. Again, no one has to pay anything for this to get their own vehicle working and the code, it’s 100% free, just requires time spent watching the video. The mobile optimized, car paint shader with alpha mask is probably worth the donation alone, even if you didn’t use the physics! Super cool shader that I demo in the video, and I had a tough time finding one online that was simplified to work well on more limited platforms.
BTW - Not just an artist. I’ve been a programmer on several professionally shipped games (check credits page). I just love making art and came from that background.
Yep. I’ve seen people on Reddit, Twitter and forums looking for something dramatically simplified in car physics. I didn’t quite hit that on this tutorial as these developers are looking for something that didn’t even use physics…just simple translations and rotations. Problem is they want that extreme simplification, but still want physics interactivity in the world, so it all has to be some kind of more complicated fake. I’m working on it, should be able to come up with something.
Not exactly sure how to incorporate steering that looks real instead of rotating around the vehicles center. I am thinking that using the front wheels center point for rotation and then using the car speed to multiply the amount of steering will cause the rear wheel to not look like they are sliding. I used a similar setup to yours to get 40 cars of traffic running on iOS at 60fps.
Easy! My script already does this in the Start() function, but to steer around the front of the vehicle you set the Rigidbody center of mass to the steering point, and down in Y axis. This way any torque forces for rotation are rotated around that point. My script is set to do this automatically, but I considered just creating a Vector3 exposed in the Inspector that a user could set this rotation/mass point themselves. I’m also considering maybe just exposing a Transform slot in the Inspector and you can just drag in this center of mass Transform and that way a user can visually see the rotation point for steering and adjust accordingly. My UniCar physics package actually uses that method.
The sliding thing can be completely eliminated or greatly reduced by adjusting the “grip” parameter on my script, combined with playing with the Physic Material assigned to the collider in the hierarchy. I simply set my own prefab up to slide all over the place as I’ve found most people repeatedly ask for drifting and sliding ability.
Yeah I think most people don’t realize how much optimizations like this could help. This idea is not original or unique to me. I’m actually implementing this idea from my experience working on Need For Speed Undercover on the Nintendo DS. We were extremely limited on the car physics, the AI, everything really. Far more limited than even the oldest iPhone. I took this trick from the way our car physics worked in that game, the player and AI were basically physics “ice cubes” sliding around the track.
Sounds like this could be usefull in games where you need to populate the entire city with cars.
But in situations where the player controls a car from the third person view point it looks unrealistic.
Although I do remember an older driving game that used this kind of physics and was pretty fun to play, but it is worth noting that this game was made to support phones with
little cpu and gpu power.
It would be hard to pass a game like that on todays market…
Yep this is not realistic by any means. This is meant for an arcade style racing experience, maybe even a cartoony kart racer like Boom Beach. I like to recall Daytona USA and the extreme popularity of that. It really depends on the style of game you would want to do, but those kind of games do pass on the app stores today and make good revenue (if well done!). Not every game will be a Gran Turismo simulation, especially so on mobile. Mobile gamers want unrealistic, casual, arcade-like, disposable experiences. Why do you think Nintendo has distilled down the Mario experience so much? It’s not even a platformer any more!