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

Car wheels turn inwards in play mode

Discussion in 'Scripting' started by square_melon5, Aug 29, 2015.

  1. square_melon5

    square_melon5

    Joined:
    Aug 26, 2015
    Posts:
    15
    Hi,
    I hope this is the right section. I've been trying to make some cars driveable. The problem with these cars is that their forward direction is set to Y instead of Z so the cars go forwards when I reverse and they go backwards when I accelerate. It is fixed by making the car GameObject a child object of an empty GameObject and rotating the car GameObject by 180 degrees. This rotation affects the wheels too, but only in play mode.

    This is in editor mode:


    and this is in play mode:


    Any suggestions how to fix it so that the wheels don't turn in? Thanks in advance for any reply.
     

    Attached Files:

    Last edited: Aug 29, 2015
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    How are you moving the cars? Can you post the script?
     
  3. square_melon5

    square_melon5

    Joined:
    Aug 26, 2015
    Posts:
    15
    I'm using a modified version of the CarController and CarUserControl scripts from the Standars Assets. I added them to the OP.
     
  4. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Try rotating the WheelColliders 180° on their y axis.
     
  5. square_melon5

    square_melon5

    Joined:
    Aug 26, 2015
    Posts:
    15
    I tried that but they remain the same. It's like the wheels locked to the same rotation as the car object.

    Edit: interchanging the wheels seems to solve it. Now the wheels turn in in editor mode and look normal in play mode, but I'm sure that there is a more professional way to solve it, so I'm open to other ideas.
     
    Last edited: Aug 29, 2015
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I normally just change the scripts if I'm using transform.translate or something like that so they are vector3.back for going forward etc
     
  7. square_melon5

    square_melon5

    Joined:
    Aug 26, 2015
    Posts:
    15
    I see what you mean, that could work but I'm not quite sure where to change the script. I think the CalculateRevs method should be rewritten, I checked the documentation about the vector3.back, but I'm just way too new to coding and I can't find out how to rewrite it to work properly (trust me I tried, I had pretty weird results, when I didn't get errors). If you could help me a little further I would really appreciate it.
     
  8. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Sorry, that script sounds waaaaaay more complicated (calculate revs before calculating movement force?) than I'm up to. I'm just starting to code this year myself so atm I just play around with the simple bits. As a rule I don't use other people's scripts unless I understand everything they are doing as that way I know I will be able to tweak it as needed. Normally I just play around with building my own. It's slow but I know what each bit is doing.
     
  9. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Maybe find where the keys are being called & swap them around e.g if they are using the arrow keys find where it is using keycode.downarrow & change it to up & vice versa
     
  10. square_melon5

    square_melon5

    Joined:
    Aug 26, 2015
    Posts:
    15
    Oh, so you are a beginner too :). Well, it is a good approach to learn and most of the time I try to write my own scripts, it just seemed easier to grab the scripts from the Standars Assets. Probably I will never be able to write a physics script like that, but I wouldn't have any problem with it if the cars had the right forward direction in the first place... Anyway, thank you for your time and help, I really appreciate it.