So last time on Fatnick Makes a Game we looked at how to fire up Unity, create a cube and some spheres, then sit and stare at the screen wondering why they won’t spontaneously form into a usable car.
This time we’re going to get that car moving!
When the car failed to move last time, I was faced with two choices: stick with the script I had initially and fix it, or try and find/build a new one. Thankfully, someone had put together a simpler car controller script, so I was lazy and switched over to that instead. Ha!
Once the script had been copied and assigned to my 4 wheel colliders…the car still didn’t move. Argh. What could be wrong? Was there still time to back out and pretend that I’d never put any real effort into making a game? But then I had my breakthrough: “Hang on!what’s all this “input.getaxis” malarky?”
To cut a long story short, it turns out that by default the control axis was being mapped to the embarrassingly obvious W, S, A, D keys. This, ladies and Gentlemen, is why you should always, always R.T.F.M.
Of course, though it was now controllable, the ‘car’ still didn’t behave like a car. Give a bit too much power to the wheels and it would take off into a somersault. Steer too harshly and it would launch into an almost endless barrel roll. Wheee.
But the good news is that this sort of makes sense. You see, the reason your car doesn’t somersault is because it’s got plenty of weight (you, the seats, the dashboard, a great big whopping engine) keeping it on the ground, with (inevitably expensive) suspension components helping to keep any lateral movement in check. My car had lots of power to relatively little weight, which is why it was essentially uncontrollable. There’s a reason that F1 cars are designed the way they are, it seems.
Alongside the physics corrections (and inserting an EXCITING reverse gear) I also worked a bit on the cosmetics. My box car is never going to be a pretty, realistic-looking automobile, but at the very least its’ wheels should roll when driving and pivot when steering. The good news is the code to get these two aspects working is reasonably straightforward. The bad news is that, for some reason, the rolling code appears to have been applied to completely the wrong axis.
At first, the wheels flopped feebly to the floor. Then, after a bit of tweaking, they spun laterally, like a coin standing on its edge. This is one to look at with a fresh pair of eyes, i think.
Overall then, not a bad couple of hours progress. Not only can the car move forward and reverse, but when it steers the front wheels point in the right direction. It can even take jumps with a degree of realism. Well, until you try and steer, that is:
So then, what next? Well, I have a feeling the wheel alignment might be off – which probably isn’t helping the sideways stability. I want to address that, get my wheels rolling forward and then look into creating some sort of artificial anti roll bar. The stunt track might have to wait for a little bit, but we’ll get there!