Monday 25 March 2013

Research - Unity Car Tutorial

I've recently been searching for a good car tutorial for Unity and found that they actually have their own!


After dabbling my way through this tutorial it seems my suspicions were not far off. There is a lot of complicated coding that goes into making a car work like this, though i would very much like to get my head around it so that we can use it. 

Something i thought I'd add (although i realise any seasoned Unity user will scoff at my ignorance) is that I've come away from this tutorial with an appreciation for how Unity simplifies the coding process. By taking the variables you define in the code itself and making them definable parameters in the inspector window you are granted a huge boost in efficiency. For example you define a variable "WheelCount" as an Integer and Unity will create a parameter with that title where you can simply input a value and the code will be updated to reflect that value. As i said this is probably a thoroughly 'noobish' discovery but as someone who finds the prospect of learning to code a bit daunting this was a pretty big thing!

Back to the tutorial, and i have to say i was a bit disappointed by the 'completed' version that it comes with and invites you to test out at the start of the tutorial. The car has proper suspension, a proper gear switching sound, skid marks, and comes on a nice looking track, it also has a very good 'drift-style' cornering technique (sometimes.) But while the tutorial itself refers to the cars 'arcadey' handling i cant help but feel that something isn't right. 

The best way i could describe the cars movement is as feeling... 'table-toppy', and what i mean by this is that the car feels like it is rotating from a single, central point. This is not how it feels all the time, mind, but certainly when turning the car it feels like the model itself turns before the car does. It also has a very strange habit of rolling forwards constantly after you've pressed the throttle button once, and when you crash at high speed you will often keep see an apparent retention forward momentum after a jockeying car comes back into contact with the ground. Gravity also seems to be at odds with this set up, as far as i can tell the car being on a slope, especially when facing backwards, will have no obvious effect when the car is still, i assume this may have something to do with the 'always rolling forwards' bug (feature?) Finally, and i may be wrong here, but i noticed that there appears to be no loss of momentum when the throttle is released, the car seems to maintain an almost constant velocity before crashing into a wall, again. I say i may be wrong because i obviously have no real experience of how a racing car behaves, not even a regular car given the fact i haven't learned yet. But during the times i have driven in my life (100% legally i swear) I've been surprised at how well a car can maintain it's speed without a foot on the accelerator, even on a flat surface.


Enough griping though, because when this arcade-style racer mockup works well it's a very enjoyable experience. On the occasions i have managed to take a corner well, making use of the drift style turning and coming out of a corner having dodged a rail by a few inches i felt a genuine thrill, and if i could make the turning experience more consistent (and less fiddly, though that may be the cost of trying to race using the arrow keys) i reckon we could have a really fun final piece on our hands!

So, if i or any or my teammates were to take on the challenge of tweaking this pre-made car setup, these are the things that would need to be changed/fixed:

- Gravity
     o Make it so the car is affected by gravity, rolling down hills, etc!
- Constant throttle/No car slow-down  
     o Make the car slow-down on throttle off

- Improve steering to feel less 'table-toppy'
     o Make the cars movement more fluid and seem more like the car is following the wheels
     o Improve the drifitng mechanic to be more consistent

Other idea's that i didn't mention above:

- Invisible perimeter along either side of the track
     o Car can be caught on  world objects very easily
     o Tweaking the car setup could fix this
     o If not, then placing an invisible wall may help

- Better camera set up
     o Camera 'sink's behind car on higher parts of the track
     o Make the camera maintain its position above the car at all times

I believe that if we could overcome these things (and possibly more that i haven't thought of!) we'd have a car setup that's perfect for our needs! However, there would still be a lot of stuff to look into on the whole 'making it a game' front if we were to use this set up:

- Laps/Lap Timing
- Opponents
- GUI
- Using a racing wheel as a controller

We would need to add all these things and probably plenty more to make this a working game, and even after all that we'd have to make our own car and level models, textures, animations etc. Though as Patrick has just shown, using a site like Turbosquid could save us a lot of time on the modelling front!

Even so i believe there'll be plenty to keep us occupied in the coming weeks.

I feel i've made a good start by working through this tutorial, i've learnt that Unity come with it's own wheel scripts and collision settings, the basics on constructing a working car setup in-game and most importantly some aspects of the workflow of using Unity.

I will continue to tweak and read the underlying code for this setup and try to understand it but at the same time i plan to look for a better and slightly more recent racer tutorial (this particular tutorial is from 2011) for Unity that may be more suitable for our needs.

No comments:

Post a Comment