Search Unity

Unity 5 - Wheelcollider wrong rotation

Discussion in 'Physics' started by mads232, Aug 23, 2015.

  1. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Hello Unity.

    Some time ago I posted a question about the unity 5 wheel colliders sinking into the ground.
    I concluded that it must've been the rotation of the wheel collider that just looked outright wrong. I got my theory confirmed when I saw this posted on twitter: https://pbs.twimg.com/media/CAx-5OkWwAA0I18.jpg:large

    You can see how my colliders looked when I asked the question back then:
    http://forum.unity3d.com/threads/unity-5-wheelcolliders-sinks-into-the-ground.339463/#post-2204318

    Here's mine now, after some deleting, editing and adding again:


    What is seriously going on? Now it's rotated on a really special angle. I swear, I did not do anything that could've made it rotate on that angle.

    The more I mess about with these colliders, the more problems I get.

    -Thanks.
     
  2. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,081
  3. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    I saw a comment that a wheel colliders up is based on rigidbody up.

    Them some odd angles you got though. Are they the scene view? (As in not playing)
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,554
    WheelColliders always point in the "forward" and "down" direction as the rigidbody they're attached to. The steerAngle value is relative to the rigidbody's forward direction.
     
    fluidcgi likes this.
  5. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Thank you for your suggestions and answers.

    JamesLeeNZ yes this is in scene view. I do have some weird rotations from blender but as it is of now, the parent object's rotation is 0,0,0. :)
     
  6. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Wait, maybe there's still some rotation issues that may make Unity think that the rigidbody's up is not my forklift's up? I'll check that out later
     
  7. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Also, can center of mass do such a thing?
     
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Are all your rotations 0,0,0 when not in play? You mention your parent, what about the rest? Ideally you will have 0 rotations for everything, including children. Ensuring that will make your life hella easier. Also make sure your pivots are centered, mainly for the wheels.

    I dont believe COM will cause your particular issue.
     
  9. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Thank you for your reply. Not all things are 0,0,0. For example the forks are rotated 270. It's been a pain in the *** to get it as it is now. The wheelcolliders are attached to a new gameObject which is placed at the wheel's center
     
  10. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    its more of a pain in the ass to work with non uniform angles imo. I know its easy to reset the pivots in 3dsmax. I assume it aint too difficult in blender. I would recommend the first thing you do is sort that out.
     
  11. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    You're god damn right. The thing is, Blender's Y and Z axises are switched. I'll try but it might take a while before I'm able to, so I'm still open for suggestions.
     
  12. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Its the same in 3ds max. If you reset the pivot, the default imported fxb will have a rotation of 90,0,0. The thing is, you can usually select all objects, reset, rotate, done. Its not hard once you figure it out.

    Why might it take a while before youre able to? youll probably save yourself a massive headache if you can.

    Incidentally, you can actually edit fxb files in Visual studio (surprisingly). Might have to be 2013 for it to work. I havnt tried resetting pivots using it, but I think you probably can (tbh I was just surprised when it opened)
     
  13. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    I know what I have to do, no worries. :) It's just that I'm busy this week so it might take a while before I'm able to.
     
  14. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    heh all good. I end up resetting pivots a lot in models, so at some point teach yourself how to do it quickly, because its something you're probably gonna end up doing a lot
     
  15. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,554
    You might try this this Blender To Unity importer.

    I've been told that a recent version of Blender has a new experimental option at the FBX exporter that resets some transforms before exporting. I haven't tried, so I can't tell for sure if/how that would work.
     
  16. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Thank you for your reply! So does your script also have the ability to fix the rotation with .blend files? I really wanna be able to use the blend files, which I just find very useful.

    I think my solution will be to rotate the entire thing 90 degrees. :)
     
  17. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,554
    My script fixes the rotations so when you set 0 degrees in Blender, it results in 0 degrees in Unity. Other angles are translated properly so the model in Unity looks exactly as it was designed in Blender.
     
  18. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Yes I am aware of that, but does this is only work when I export it as fbx or can I use the .blend file? I don't export to fbx
     
  19. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    So I tried turning the forklift -90 degrees in blender, which it did not like:



    Although by dragging in just the prefab I got the result I wanted. I'm going to try and copy all of the scripts, colliders and everything over to the new one I just created. Then I'll see what the result will be.
     
    Last edited: Aug 30, 2015
  20. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Now, this looks promising! The wheel colliders looks like they should now.
     
    Last edited: Aug 30, 2015
  21. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    But, now my child object's position (wheel mesh, steering wheel etc) is set to 0,0,0! What the heck is going on here?!

    I need those to position the wheel collider!
     
    Last edited: Aug 30, 2015
  22. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    You should be able to change the pivot without changing the rotation of your meshes.

    Make sure you delete prebab and re-create after re-importing updated model
     
  23. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Well now when I import it, it's automatically rotated -90, but when I remove that, it's as it should be. (0,0,0 rotation) Why does it rotate to -90 itself?

    And the position is still 0,0,0
     
  24. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    So the wheel colliders looks like they should in the scene view, although it just jumps all over the place and through the floor in play mode. I of course expect this to be the settings, so I'm going to figure that out. Got anything on the child position thing?
     
  25. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    This is what the wheels does when in play mode:

     
  26. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Update: I commented out my "visualize wheelmesh" code, and now it looks fine.
     
  27. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    I still need to fix the position thing though. It messes up the whole thing. Please. Anyone?
     
  28. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    did you delete it from scene and re-add?
     
  29. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
  30. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    are you using GetWorldPose to move your wheel meshes?
     
  31. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
  32. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    I think it's the position thing that is messing it up. I've never had this position thing happen
     
  33. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    where are the colliders? Are the wheels positions matching the colliders position?
     
  34. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    The above (post #25) only happens when I add the "visualize mesh" thing. (GetWorldPose)


    The colliders are just where they should be

     
  35. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    hmmm.. that' quite strange. tbh, there's not much more I can suggest.

    if you want, send me the forklift model and ill import it tonight and fix it up as required.
     
  36. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    I could, although I would really want to see what you're going to try. For my own learning purposes. I can send the file, but I would appreciate if you told me how you fixed it afterwards :) Do you have skype or something? PM me with a username.
     
  37. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    np, pm sent.
     
  38. Manav-Chaudhary

    Manav-Chaudhary

    Joined:
    Mar 5, 2016
    Posts:
    1
    if you want any handle on wheel collider then attatch rigidbody to that gameobject on which you are applying wheelCollider
     
  39. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    694
    That is the reason i dont use 3d max or blender, i use Cinema 4D Rxx is better, i set axis to 0,0,0 and stay that way in Unity.