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

Example project: wheel collider car

Discussion in 'Scripting' started by jkreijkamp, Aug 17, 2008.

  1. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    You can now freely download my test project JCar (the only restriction is that you don't reuse the textures, sounds and models in commercial projects, you can do with the scripts whatever you like).

    The code contains a wheel collider car, particle system for showing collisions, dashboard items and several other (hopefully) useful stuff handy to get a head start when building something with cars in unity.

    I really would like to get feedback and especially improvements to the car physics are very welcome, I'll try to update the project with useful changes that are not too difficult and time consuming to port back in to the demo project.

    The source files can be found at http://ctrl-j.com.au/pages/jcarsrc.html and a ready build demo at http://ctrl-j.com.au/pages/demo.html.

    By the way, (most of) the code is in C#.
     
  2. northman

    northman

    Joined:
    Feb 28, 2008
    Posts:
    144
    :D :D
    Thank you!

    I'm learning phyx wheel collider, it's very helpful.
     
  3. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45

    Does it running on iPhone well?
     
  4. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    It seems to work okay but needs a few small modifications because unity iphone uses older C#/.NET version. I just uploaded my jcar/iphone experiment I did a few months ago and changed the models from .jas to .fbx so more people should be able to use it. You're free to do whatever you want with the code, but it would be nice if you acknowledge me or at least let me know about your project. As I have the iphone development license and ipod touch I'm happy to try out your code, my UDID is: 96e02bf2e448aa208e6a6113ccf02bfe2a712b7e

    The source code of NumberRacer (yeah, had an idea but didn't have time, same story as usual) can be found at

    http://ctrl-j.com.au/pages/jcarsrc.html

    Jaap
     
  5. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    I was learn JCar and gettin stucked in steering, wheel and moving backward.
    When car hit something it won't move backward n keep forward, so everything stucked and get to endtask.
    Is there any sample code or guide references for creating moving backward acceleration on JCar iPhone?
    Any suggest would so appreciated.
    Thanks all.
     
  6. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    You should be able to drive backwards by tilting the screen towards you. It sometimes helps to push the break first (touch screen) so you're stopped fully. Just tested it and it does work. However the app is quite unsupported as I haven't tried yet if I can still build it with XCode for the 3.0 beta 2.
     
  7. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    Sorry, it didnt work jkreijkamp .. instead when I tilted the screen towards, the car only make a jump movement but it still stucked by object front of it...
    Is there any references for creating moving backward acceleration?
     
  8. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Strange, it works for me, but basically backwards movement is a negative torque to the motor. My JCar code simulates a gearbox that's put into reverse, which results in negative torque's instead of positive ones. Did you by any chance change the code to a manual gearbox (should be a checkbox in the car properties)? Are you maybe testing in the simulator? If so, I think the 'home button' should be on the right side when holding the iphone in remote app. As I said, haven't got the means now to test it, but if I find time for it i'll have a look.
     
  9. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45

    Where I should change the 'gearbox' code?
    Please show me the reference script location, since I do couple change last day it made me dizie :cry:
    Thx
     
  10. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Basically, the CalcPower function in JCar determines the power returned by the motor for the current gear, a negative value for reverse (basically rev. gear (gear 0) is the same as gear 1, but with - sign).

    the FixedUpdate function in JControlledCar handles the up/down shifting (and throttle + steering). Although probably unreadable on the iphone screen, the RPM gauche also has the gear indicator, R for reverse.

    I'll upload a new version of the JCar for iPhone because aparently while changing the models from .jas to .fbx I forgot to reconnect the meshes of the mesh collider. Should be fixed now. Also in the player with remote I can reverse the car as it should, so it looks like you manage to 'break' something.

    Jaap
     
  11. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45

    Thanks jkreijkamp,
    I'll try for reversing gear technique while wait for ur uploaded file.
     
  12. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
  13. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    Thankyou jkreijkamp . . . really helping.
    I'll post the progress soon.
     
  14. tewe76

    tewe76

    Joined:
    Mar 14, 2009
    Posts:
    52
  15. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    This is the iPhone version of JCar, the JCar for normal unity is at:

    http://ctrl-j.com.au/pages/jcarsrc.html, choose JCars-src-080821.zip. If I find time and energy i'll update the unity and the iphone versions soon with easier versions of the scripts, but don't hold your breath :)
     
  16. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    Nice job jkreijkamp ..
    Your Jcar iPhone works great, especially when the car get jumping on a slider .. my questions :

    1. How to show the car dashboard? Should I make changes in JCar Controller and Camera View code?
    2. What tools you use for creating the building object? When I tried create using 3dsmax2009 than convert into obj/fbx, it failed. The car goes through and pierce the building object...
    :(
    Any suggest?
    Thanks
     
  17. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    1. with showing the dashboard you mean the casing around the dials and stuff? One way is to make a simple 3d dashboard and place it at the place where I also put the dials. The dials are just simple 3d objects with their own camera that renders in the bottomleft of the screen. An other solution would be to make an image that is rendered with one of the image render calls.

    2. The objects are made with Cheetah3D a cheap but reasonable 3D app for Mac. The app has also generated the shadowmap. The same mesh is also used for the mesh collider (one collider for the ground mesh and one for the buildings), so make sure that you also map the collidermesh to the new mesh you imported.
     
  18. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    Would you like to provide the url/site reference or step by step how to export the cheetah3d object into compatible object in iPhone include the .mat file?
    Thanks.
     
  19. daynie

    daynie

    Joined:
    Mar 31, 2009
    Posts:
    45
    Hi
    Is there anyone can inform about scoring code in Jcar?
    Any suggest would appreciate.
    Thanks all
     
  20. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Thanks for sharing the JCar project.

    You mentioned that it has a wheel collider car model but I am unable to find the wheel colliders on the project.
     
  21. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    The wheelcolliders are created by the script.
     
  22. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Thanks, now I see them.

    Why are they created by the script and not present on the scene editor?
     
  23. Randimonium

    Randimonium

    Joined:
    Jun 27, 2009
    Posts:
    17
    Thanks for the example project, jkreijkamp. You are a credit to the game dev community.
     
  24. OXYGEN

    OXYGEN

    Guest

    Joined:
    Mar 16, 2008
    Posts:
    1,101
    thanks for sharing the script dude you saved me bucket loads of time!

    :D