Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Generic Car Prefab

Discussion in 'Works In Progress - Archive' started by ahillel, Aug 29, 2013.

  1. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Hi,

    I've been working on this for the last couple of weeks.

    Please visit my blog to get download link and more details:
    http://unityassetier.com/?p=135

    My idea for the perfect car prefab is a generic one with place holders for meshes, which you can use on basically any car model.

    It supports:
    Driver’s steering-wheel. [Done]
    Wheels alignment. [Done]
    Rear lights. [ToDo]
    Front lights. [ToDo]
    Car Physics, Wheel Colliders. [Done]
    Engine gear ratios fine tune. [ToDo]
    Engine gears audio system. [Done]
    Skidmarks tire-smoke system. [Done]
    Mesh deform on collision. [ToDo]
    Handbreak. [ToDo]
    Easy-to-use Unity Editor UI. [ToDo]
    Center-of-mass setting. [Done]
    Speedometer, calculates KPH/MPH. [Done]

    Need help with:
    Mesh deform on collision. I wrote some code that supposed to handle that, but not working good. More complex methods should be added in order to make it work.
    Engine gear ratios fine tune. The system functions, though I’m not sure it will on large variety of possible cases.

    Please feel free to share your thoughts and ideas.

    Thank you.
     
  2. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I would like driver's seat view camera.
     
  3. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    Great work!
     
  4. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Hi Jeff,
    Thanks. Was thinking about it. Will be added.
     
  5. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Impressive work, I just went for a spin!!!

    $car.png
     
  6. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Great! Have fun! :)
    Hope some of you could help me solve the mentioned tasks :)
     
  7. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    How should I model the car body and wheels in 3D Studio MAX so that when I add the car body and wheels to Generic Car Prefab, the car body and wheels appear correctly? I tried to add a car body that I modeled to Generic Car Prefab but the car body is rotated so that its front end is pointing down instead of pointing in correct direction. I tried the Generic Car Prefab and it worked better than other people's car prefabs but it's not fast enough.
     
  8. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    @Jeff: Just rotate the car in the inspector.
     
  9. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Jeff, Like Carking1996 said, as a simple solution, you can simply rotate the body. If it faces down I guess you need to rotate X -90.
    Wheels should be simply not in the same mesh as the body, so you could replace the prefab's wheels. If you want faster car you can raise Engine Torque property, though I can't yet guarantee it'll work smoothly, as project is still in early stage of development.
     
    Last edited: Sep 2, 2013
  10. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I increased max RPM to 5000 and torque to 50. The car ran faster and won't flip over on hard turns. That is much better than other people's car prefabs where cars flip over on hard turns. I thought that I have 3D mesh files of car bodies but I couldn't find them.
     
  11. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Great. I'll try that too :)
    You can find some free models at the Asset Store or at TurboSquid.com
     
  12. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Yeah, Engine Torque 50 and MaxRPM 5000 works nice. I liked the feeling of Engine Torque 40 even better.
    Though, when I ran it, it did flipped over after going over top gear [theoretically] maximum speed. That makes sense becuase this limitation is still missing in the prefab. I'll put this in the next update.
     
  13. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    How should I put different wheels on the car prefab? Your car prefab appears to have a body that was part of the car that was included in the Unity Car Tutorial but the body isn't in the scene.
     
  14. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    You can replace the children of Wheel objects. This kind of actions are basic in Unity. Maybe you'll prefer to watch some Unity video tutorials on YouTube.
     
  15. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I replaced bodies and wheels with my own bodies and wheels. I deleted bodies and wheels that came with Generic Car Prefab. When I play the game, I get "NullReferenceException" message that may have something to do with the Deformer script.
     
  16. Divinux

    Divinux

    Joined:
    Jul 5, 2011
    Posts:
    205
    Jeff, without knowing how it all works, I'm guessing that after deleting the original wheels the carscript (or the deformer script) doesn't know where the wheels are. Find where the script in question is attached to the gameobject and check if everything in the Inspector is assigned properly.

    Will comment on the thread once i had more time to play with it. Its a great idea regardless.
     
    Last edited: Sep 5, 2013
  17. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I think that the names of 3D meshes don't match those in scripts. Any suggestions?
     
  18. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    Yes. Porbably. Change their name to the prefab's original names. And make sure to tie replaced objects to correct public properties in script.
     
    Last edited: Sep 6, 2013
  19. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
  20. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I downloaded the update and the car worked better than before but I think that the headlights are not working. I found out that if I delete the "Body" object from the "GenericCar" hierarchy, I get the "NullReferenceException" message. I think that the "Body" is an empty game object.
     
  21. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    You are not supposed to delete "Body". You have no reason to do that at this point, as "Body" is just a place holder at the moment. Or at least replace it with other "Body" object. NullReferenceException means that the game is looking for something it can't find. Usually an object that has been removed, deleted or modified wrongfuly.
     
  22. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    Is the hierarchy correct?

    $van40.PNG

    What about "BodyCollider" object?
     
  23. ahillel

    ahillel

    Joined:
    May 22, 2011
    Posts:
    34
    It looks ok. Does it throw any errors?
     
  24. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I created a new project, imported the Generic Car Prefab package, made sure that the generic car worked before replacing bodies and wheels with my own. After replacing bodies and wheels with my own, the new project didn't give me any error messages. In the old project, I made a mistake of removing the body object and I got error messages. I added the driver's seat view and "Mouse Look" script to the project and it worked.
     
  25. wana7262

    wana7262

    Joined:
    Jul 2, 2012
    Posts:
    101
    download link please....
     
    Nomibuilder likes this.
  26. Nomibuilder

    Nomibuilder

    Joined:
    Apr 24, 2014
    Posts:
    20
    download link Please?
     
  27. BestUnity

    BestUnity

    Joined:
    Aug 31, 2013
    Posts:
    2
  28. Nirav-Madhani

    Nirav-Madhani

    Joined:
    Jan 8, 2014
    Posts:
    27
    For
    Need help with:

    Mesh deform on collision. I wrote some code that supposed to handle that, but not working good. More complex methods should be added in order to make it work.
    Engine gear ratios fine tune. The system functions, though I’m not sure it will on large variety of possible cases.

    Please feel free to share your thoughts and ideas.

    Thank you.

    You Can Check this asset
    https://www.assetstore.unity3d.com/en/#!/content/8228