Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Car Will Not Drive On Mesh Colliders

Discussion in 'Scripting' started by jakeomonk, Jul 27, 2014.

  1. jakeomonk

    jakeomonk

    Guest

    I have created a car with the script below attached and it drives perfectly on a flat plane or terrain but when I try to drive the car on top of a mesh collider on a mesh created in Autodesk Maya it seems like it has trouble accelerating and the wheels turn but the car does not, the car drives a lot slower and if I turn up the speed and turn speed it drives but not well, this is really confusing me and I think it could be something to do with the two colliders conflicting with each other.

    Car Script: http://pastebin.com/fF5XykuM
     
  2. domkia

    domkia

    Joined:
    Aug 19, 2012
    Posts:
    99
    If you got this from James then I think I know what the problem is. I had similar issue and found that this is supposed to work only on flat surfaces (if i'm not wrong. But when I tested it, it wasn't working properly when the car was rotated / flipped ), This is because the slip compensation and other forces are applied in world space not relative forces, so if your car is lets say climbing to the mountain, these forces could give you weird results. I would recommend you to convert all forces to relative.
     
  3. jakeomonk

    jakeomonk

    Guest

    How would I do that?
     
  4. domkia

    domkia

    Joined:
    Aug 19, 2012
    Posts:
    99
    Instead of using addForce, use addRelativeForce. Also you need to convert some vectors to local aswell. Try inverseTransformDirection. Now Its a matter of tweaking, testing and debugging. Hope this helps a little.
     
  5. jakeomonk

    jakeomonk

    Guest

    Okay thanks I'll give it a go.
     
  6. jakeomonk

    jakeomonk

    Guest

    Okay so I have swapped out the addForce for addRelativeForce but I'm struggling to understand which vectors I should change and what swap them for, if you would be able to include some sample code that would help a hell of a lot.