Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Car Tutorial

Discussion in 'Community Learning & Teaching' started by antenna-tree, Apr 24, 2010.

  1. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Hey,

    We're proud to announce a new Car Tutorial for everyone to check out and hopefully learn a lot from.

    This in-depth tutorial will take you through all the necessary steps to create a fun arcade style race car mechanic.

    Section 1 - Assembling the Car
    How to assemble a Car Prefab from a 3D model, scripts and components.

    Section 2 - Tweaking the Car
    How to tweak the car to behave "better" or in different ways.

    Section 3 - Under the Hood
    A more in-depth look at the actual code that drives the car.

    The tutorial project also includes a high-end physically accurate and realistic car model. Use this if you want to make more simulation-like games.

    We hope you like it!
     
    ra2227126 likes this.
  2. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    Heya! :O)
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    COOL :D

    Edit: Okay, I just played it... And words can't even describe it's amazingness!!!
     
  4. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    Pretty nice!

    I encountered some heavy graphical glitches though. I'm not sure if things are going wrong on my end or if the demo scene is flawed in some way. I'm using Unity Basic, windows 7 32bit, with an intel core 2 duo, an nvidia geforce 9800, and two gigabytes of memory, so no stone-age hardware or anything.

    This is my in-editor view of the complete_scene: http://www.synthode.com/webjunk/unity_car_demo_bugs.png

    First off, the water's not rendering properly. It just shows a normal map rendered in screenspace wherever the water plane is visible.

    Second, the scene view has two permanent overlayed renders of the terrainmesh on the lefthand side.

    Third, the game view has similar problems, but they go away once the game starts.

    Here's the full error text:
    Code (csharp):
    1. screenviewcoord[1] < 0 || screenviewcoord[3] < 0
    2. UnityEngine.Camera:Render()
    3. UnityEngine.Camera:Render()
    4. Generate2DReflection:UpdateReflection() (at Assets\Scripts\CSharpScripts\Generate2DReflection.cs:70)
    5. Generate2DReflection:LateUpdate() (at Assets\Scripts\CSharpScripts\Generate2DReflection.cs:40)
    6.  
    7. [..\..\Runtime\Camera\CameraUtil.cpp line 37]
     
  5. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    thank you :!: :!: :!:
     
  6. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Ooo cool, have to check this out, thankyou :)
     
  7. GuidoVanSanten

    GuidoVanSanten

    Joined:
    Apr 8, 2010
    Posts:
    5
    This is wicked stuff!
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No glitches here, and I do have a stone-age hardware (or at least bronze-age: G5, ATI X800). I have Pro, and this tutorial does use some Pro effects, but they should be disabled and not have any effect without Pro. Actually one glitch: the road surface disappears if quality is set to Good, but appears at all other settings.

    (Speaking of my stone age hardware, even with the settings maxed and running at my desktop res, it manages 20+ fps. If I lower settings and resolution a fair bit it will go a little over 100fps and doesn't actually look much worse. So good job optimizing that; I'm sure it's much faster on a recent machine.)

    I poked around a bit and it looks like the SoundToggler script for the tunnel wasn't finished. I think it was supposed to be something like this:

    Code (csharp):
    1. var fadeTime : float = 1.0;
    2. private var soundScript : SoundController;
    3.  
    4. function Start () {
    5.     soundScript = FindObjectOfType(SoundController);
    6. }
    7.  
    8. function OnTriggerEnter () {
    9.     soundScript.ControlSound(true, fadeTime);
    10. }
    11.  
    12. function OnTriggerExit () {
    13.     soundScript.ControlSound(false, fadeTime);
    14. }
    The effect is more audible if you use the tunnel_boost sound instead of the other tunnel sound.

    If anyone wants a Pro build to play around with, here is a universal build for Mac. I disabled the performance tweak script because I don't like the quality going up and down at runtime, so it probably won't run very well on Intel graphics. Also a Windows build here.

    --Eric
     
  9. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Yay, no more vehicle questions in the scripting section asking how to make a car. You guys are the amazingist.
     
  10. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    This is awesome. I am really impressed by Unity's very excellent tutorials which are of such high quality. I'm also really impressed that you guys put so much time and effort into creating these significant projects, with all the content and models and everything, and then release it freely to the public... I know it's an investment for you in making Unity a more appealing product and that this has definite benefits for future business, but still, it's very nice to be led through how to build these great projects and it really opens up a whole world of possibilities and new skills. Thanks!
     
  11. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    Amazed here too!!
    No glitches - i get ~120fps at 1600x1200 with "fantastic setting" (9800GTX). Haven't seen such professionaly looking/working (car mechanics like) thing on Unity till yet. TOP JOB !!!
     
  12. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
    Looks good! Definitely one of the better looking car oriented Unity things I've seen.
     
  13. Ayce

    Ayce

    Joined:
    Jun 8, 2008
    Posts:
    101
    YAHOOO!!! :D
    Unfortunately, for me, I have to go to work soon and don't have time to look at it right now. :cry:
    Oh well, I'll have a go later.
     
  14. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    I am not going to do car game real soon but ohh 1000 thanks to put such wonderful resources so we can learn a lot ;)...specially me :D
     
  15. oem

    oem

    Joined:
    Jan 8, 2010
    Posts:
    12
    Thanks! I wanted to try make a car game :D
     
  16. MatthewJCollins

    MatthewJCollins

    Joined:
    Dec 3, 2009
    Posts:
    372
    Thanks, this should be quite helpful.

    I too am getting the errors though. The game will play ok, but the scene view and game view goes all screwy for me. Below are a couple of screen grabs.

    I am running XP Pro and have an ATI Radeon HD 4850 card. Oh, and I am using the free version of Unity, not Pro.
     

    Attached Files:

  17. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Hi guys,

    Glad most of you are enjoying the new Car Tutorial ;)

    If you're having any issues with the tutorial please submit a bug report. This includes graphical errors as well as unclear passages in the tutorial itself.

    You can do this by going to the Help menu, selecting "Report a Problem", and filling out the necessary info.

    We try to weed out all the glitches before we release something like this, but we're obviously not perfect. The quicker we get good bug reports in the quicker we can fix the issues.

    Thanks!
     
  18. Ayce

    Ayce

    Joined:
    Jun 8, 2008
    Posts:
    101
    Having the same problem here. I'll post a bug report momentarily, with a screen shot of the console.
    I wonder if it could be an ATI thing, I just had the driver crash. (HD 2600 PRO)
     
  19. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    @Dele: Yep, that's exactly what I'm getting. It seems that everyone that's getting the glitches is running Unity Basic, I think.

    @aNTeNNa trEE: Submitted a report. :)
     
  20. Wadoman

    Wadoman

    Joined:
    Dec 8, 2007
    Posts:
    336
    yeah Im on Pro and it runs perfectly.
     
  21. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    wow, this new resource, is way way beyond awesome!!, i have been struggling with vehicles and the infamous wheel collider for soo long, now i can see what i was doing wrong.

    i can now keep making progress

    thank you so so much, you rock the world 8)

    A+++++
     
  22. Ayce

    Ayce

    Joined:
    Jun 8, 2008
    Posts:
    101
    Well that could be it, I'm on basic (free) as well. I'll just ignore it for now.
    :wink:
    I have to try this on one of my cars and tracks anyway, so it could be some pro asset causing the issue.
    On that note, I think I found out what was going wrong with my imported car's wheels. Unity wants the z axis pointing forward, while Max sets it to the side. :roll:
     
  23. Route 66 Rambler

    Route 66 Rambler

    Joined:
    Mar 12, 2010
    Posts:
    45
    This is a GREAT tutorial. I just spent a couple of months getting my driving game to a usable state, starting out with the tutorials by Andrew Gotow and a few others, and rewriting, adding functions, and tweaking from there.

    I already have worked out a very nice driving model, but I've been looking to add some different functions and behaviour to it. This tutorial has given me new ideas on how to work those ideas, and showed me how to work out a few things I have been studying the manuals with. Thanks for this great resource. My cars and track are running and looking better already using some of your ideas.

    I have been have a "feature" come up with basic free Unity. My main system is older, with the Intel onboard graphics, and the Pro Reflective shaders make it crash every time I try to load the Dodge Charger to have a look. My other two systems have less ram, but with the GEForce cards run fantastic with great performance.
     
  24. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    Just tremendous 8). Thanks for making this tutorial public Unity.


    Peter.
     
  25. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    110
    Great effort!

    A fine-looking road system, a nice waterfall example and the camera script are my favs in this project.

    A small glitch that I noticed is that the camera in some cases lerps continuously between "going-to-the-front" and "going-to-the-back" of the car and does not result in some state. I didn't have time to check if it's just a configuration issue.
     
  26. gamenut30111

    gamenut30111

    Joined:
    Nov 7, 2009
    Posts:
    399
    very nice job, i might start up with this next, after my rts pack is done, i might start an fps game.
     
  27. coin-god

    coin-god

    Joined:
    Jan 21, 2010
    Posts:
    325
    I must say its incredible, great work guys.

    I only see sometimes the car wont stop 100%, and keeps moving forward slowly, and the camera glitch someone mentioned.
     
  28. Armagon

    Armagon

    Joined:
    May 29, 2009
    Posts:
    246
    There are few problems with physics, specially when the car goes flying through air, but i guess that's Unity 2.6's fault and hopefully will be fixed with the new implementation of PhysX on 3.0.

    One thing: i guess not only me, but other artists as well, would love to see some workflow, making of or even a tutorial for the racing track. It looks amazing!
     
  29. Rewii93

    Rewii93

    Joined:
    Apr 1, 2010
    Posts:
    16
    Graphically awesome, but in my opinion... the car controls are really unnatural. The car rotate weirdly, the suspension is not really accurate, and sometime the car just fly in the air ;\. But it's good looking.

    Rewii93
     
  30. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    @Rewii93

    I don't know, I find it quite accurate to real life physics, and less accurate to gameplay physics. More like a simulation game.

    If I were to make a car game, I would use this as a basis and make it completely on the play factor.
     
  31. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    I 100% agree but I think these guys are basing there opinion off of the included physics instead of the advanced physics that you have to manually apply to the car.
     
  32. Ayce

    Ayce

    Joined:
    Jun 8, 2008
    Posts:
    101
    True, Ken.
    I've read through the tutorial and it states that some things will need to be "tweaked" to your liking/needs(see section 2). Definitely a good starting point. In my opinion, the only things missing are a start/finish line and a lap counter/timer, but they could be scripted in later.
    Next step for me is to try the scripts etc on my test car. It isn't made quite the same as the car in the tutorial, so it could be a challenge. if all else fails, I'll import the Challenger into my scene and go from there.

    :wink:
     
  33. Maurice-Hoffman

    Maurice-Hoffman

    Joined:
    Jan 22, 2009
    Posts:
    182
    I use my own car with the tutorial and now i am getting an error:

    NullReferenceException: Object reference not set to an instance of an object
    Car.UpdateWheelGraphics (Vector3 relativeVelocity) (at Assets\Scripts\JavaScripts\Car.js:315)
    Car.Update () (at Assets\Scripts\JavaScripts\Car.js:93)

    And only the wheelcollider appears for the front left wheel and the collider appears at the center of the car, but the wheels all have their center in the wheel.

    What am i doing wrong ??
     
  34. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    Really nice tutorial, and just in the right time for me. We just started working on a small hover-car racing game a week ago and I was struggling with the driving model.

    Does anyone have any suggestions how to tweak the car model from the tutorial, to feel more like a hover-car(with a jet engine on the back)?
     
  35. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    There's a script in this thread which does that. Hovercar physics is generally much more straightforward than real car physics, so it's probably easier to start with this than to adapt the script from the car tutorial.
     
  36. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    I tried that script andeeee. It doesn't work if the surface beneath is not flat. It just starts flying around erratically.

    And even if it did work, it still needs a lot of tweaking to get that hovercar feel. (which is something I've been trying to do for a week and I just can't get it right). I don't think it's the right approach trying to simulate actual hovercar conditions. I'm looking for that Wipeout feel.

    The car tutorial physics actually seem to give me a nice starting point. I feel I could get good enough feel, with a little bit of tweaking in the right places.
     
  37. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Time to roll up your sleeves and get it done on your own! Take the new tutorial, and the other script which doesn't work and get to sorting it out! Not everything is ready to be handed to you so let you be the first here! :)
     
  38. POLYGAMe

    POLYGAMe

    Joined:
    Jan 20, 2009
    Posts:
    196
    Great tutorial and works SWEET on my five year old Powrbook 1.67. BUT it really only covers what is already readily available in many other tutes - a single car and the physics of said car. What about setting up opponent cars etc? that's the stuff I know I'm gonna get stuck on. I have a car model up and running already but I would like more info on the other aspects of a racing game... enemy cars, countdown timers, lap checkpoints and the like....

    Forgive me if this stuff IS included (I only had a brief glance at the tute today) and also, I really do appreciate this... great quality all round! I'm probably just asking too much ;)
     
  39. AaronH

    AaronH

    Joined:
    May 10, 2009
    Posts:
    9
    In case this helps anyone else applying these scripts to their own models..

    My vehicle's wheels were sinking into the ground, then going back to normal in the air. This was partly due to the fact that the wheelRadius variable is being hardcoded at 0.4. Worthwhile to make that not private I think, depending how your model is set up.

    Also had to change where the collider was getting its radius:
    wheel.collider.radius = wheelRadius;

    ...instead of grabbing it from the tireGraphic.

    Thanks for a great tutorial!
     
  40. Rasenger

    Rasenger

    Joined:
    Nov 17, 2009
    Posts:
    32
    I have a strange problem when making a car using my own models. I have a basic go-kart frame and tires, made them using Blender. Tires have correct center point. I had to make empty game objects for every wheel so that I can get the car script to accept them. When I run the game (car drops on a plane that has a box collider) the wheels pop off and move to strange places but the car handles as it should. Here's some pictures:

    What the f
    http://i4.aijaa.com/b/00298/6146738.png

    That's my setup
    http://i7.aijaa.com/b/00880/6146747.png
     
  41. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    Rasenger

    I had the same sort of problem with my skinned mesh. All wheels got centered on the root-bone. To work around this behavior I took the wheel rotation code from Jcar and implemented it inside the UpdateWheelGraphics function.



    Peter.
     
  42. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    This is brilliant!!!

    I have never (EVER) wanted to make a driving game but I do enjoy playing them... I'm now having other ideas!

    Well done,
    Matt.
     
  43. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,359
    I allways have inverted camera. Why ?
    Just download and run and see that

     
  44. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,359
    If I set Good Quality, all work fine.
    I have Unity Pro and my videocard is GF 9800 GTX+
     
  45. ScripterU

    ScripterU

    Joined:
    Jan 13, 2010
    Posts:
    14
    Maybe you have "Field of view" of you camera in a negative value.
     
  46. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,359
    I just download and open the project. I have download it twice.
     
  47. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I like the car tutorial although I haven't actually done it yet ;-D Too busy playing around with the demo.

    Just wondering though... what if I wanted to have, say, 8 cars all visible at once, would it bring the engine to a major slowdown? Talking about pretty average hardware... the 1-player demo gets about 40-50fps on my system in `good` mode and about 25 in fantastic.

    Each of the cars would have the same kind of physics as in the demo. Is it too much physics?
     
  48. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    infinite thanks!!!

    Need to try it!!! sadly I'm now in an ubuntu pc!!_ :evil:
     
  49. Route 66 Rambler

    Route 66 Rambler

    Joined:
    Mar 12, 2010
    Posts:
    45
    For those of you having a problem with the wheels moving away at the time you hit play, this might help.

    Make sure the wheel meshes have their centers at the wheel centers, not the center of the car.

    Select the wheel you wish to work with, in the top view. Hit F to focus on that wheel. Make an empty GameObject, and your recent hit on the F button should make it appear at the wheel center. If not, move it to the wheel center.

    drag the wheel mesh in the heirarchy into the empty game object. This parent object is where you place the "Wheel" script in the alternate model, and the object you choose as a wheel in the main car script, whether the included one or in the alternate physics "car controller" script.

    On the rear wheels, I have to nest the parent to the wheel mesh inside another empty game object in the same place. The wheel script still goes on the game object that is the parent of the wheel mesh. You still choose that game object for the car script. The additional game object stands in for an axle position on the back, basically. At least that's how it seems.

    I'm going to re-work the reverse gear on both of these scripts. My game is an open ended driving game instead of a race, and actually backing up can be worthwhile. On the included script the reverse shoots forward when released, and doesn't seem to work at all on the alternate model.

    I also don't like the way the car stabilizes itself in the included script, if you are turning while jumping over a hill, like with a baja bug or a dirt bike, it counter-rotates in a very non-intuitive way while the vehicle is in the air, or when the front wheel or wheels are off the ground, like a wheelie or a strong bump.

    Overall, though, the whole tutorial is GREAT!
     
  50. siliwangi

    siliwangi

    Joined:
    Sep 25, 2009
    Posts:
    303
    I confirmed about the artifact glitch(grey and flying small debris of vertex) also a second strange overlay with pure grey on it o_0;,you can see through the object behind it and somehow in this strange 2nd overlay the cartesian cordinate not appear,reported here : http://forum.unity3d.com/viewtopic.php?p=320888