Search Unity

Isometric racing game and sliding/drifting while turning

Discussion in 'Physics' started by Claudio-Forain, Nov 27, 2014.

  1. Claudio-Forain

    Claudio-Forain

    Joined:
    Nov 27, 2014
    Posts:
    4
    Hello all. I'm pretty new to unity and game development in general, but I've already got a cartoonish running around a course. But the problem is that the car is too "obedient" if you know what I mean. The car steers as soon as I hit the turn key, and I would like the car to slide/drift, much like in Rock and Roll Racing and its remake, Motor Rock (the turn behaviour I expect is here:
    )

    First, I tried to use addTorque, and after I used steering with wheel colliders, but its not quite there yet. I don't know if I should use physics or transform to get this behaviour. Any tips? Thanks in advance.
     
    Reaksmey-Rt likes this.
  2. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    My advice, if you're doing anything with physics, is to do EVERYTHING with physics. At least, as far as possible. It's pointless trying to simulate these things in code because you're unlikely to ever get it to look right, and it will perform a LOT worse since you're reinventing the wheel and trying to write physics in high level code, instead of using the native simulation engine.

    With a vehicle only the tyres should touch the bottom. So try assigning a physic material to the tyres, (and also the track) and tweak the friction values on those

    Aside from that, your vehicle should move by applying a force in the direction that the tyres are facing. Then when you turn it, just turn the tyres, and the trajectory will correct itself, but momentum and friction will do their thing naturally.
     
    RJ-MacReady likes this.
  3. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Agreed, learn to use the built-in wheel colliders and stick to the book with the physics engine! If you're getting bad behavior, it's because you've engineered something that wouldn't work in real life, either! :(
     
    Nanako likes this.
  4. Claudio-Forain

    Claudio-Forain

    Joined:
    Nov 27, 2014
    Posts:
    4
    Thanks for the replies. I am already using wheelcollider, and for now what I did was trying to tweak the wheelcolliders sideway friction, but its still not quite there yet.

    About this: " So try assigning a physic material to the tyres, (and also the track) and tweak the friction values on those"
    I thought about that, but then I read the following here (http://docs.unity3d.com/Manual/class-WheelCollider.html):

    "The Wheel Collider computes friction separately from the rest of physics engine, using a slip-based friction model. This allows for more realistic behaviour but also causes Wheel Colliders to ignore standard Physic Material settings."

    From what I've read, all I can do is decrease overall wheelcolliders stiffness, so they will slide and drift more based on less forward and sideway frictions. Is the documentation outdated or did I misinterpreted something? Thanks once again for the replies.
     
  5. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    I doubt you've stumbled upon something that is broken in Unity. In fact, I strongly doubt it. I don't think there's an issue with the documentation, either. Many people have games online built using these same things you're working with, and I've played years old demos of cars with all of the features you're describing.

    That said,



    There's a lot here and I have gotten working car models and I still don't remember what every value means. If you knew what every value here meant and how it was implemented, you could definitely get your project working. It's just a lot of reading and experimentation, if I recall, to figure out everything exactly how you want it. That drifting effect comes from the tires moving rapidly (thus reducing friction) while heavy mass is trying to continue in the same direction. So, if you're modeling that in the engine, that should be the effect you're getting.
     
  6. Claudio-Forain

    Claudio-Forain

    Joined:
    Nov 27, 2014
    Posts:
    4
    I didn' t want to imply that was Unity's fault that I cannot get my project to work properly, I just thought that maybe with the new version (4.6, I guess) maybe something was different, as Nanako suggested something that went directly against the documentation (as I cited previously).

    About the settings in wheelcollider, I did read what they were and understood how its function work, and despite that I didn' t suceed, which brought me here =) . Also, if you got the wheelcollider to behave the way I described, It would be much appreciated to see your collider settings, if you don't mind sharing.

    That being sad, I think that my problem is with the mass of my car and the way that Im speeding it up.
    I'm simulating the gas pedal by applying a forward force, and the mass of the car is 10. The problem is that I don't understand what exactly 10 means. 10 what? lbs? kgs? unicorns? I will try to tweak its mass and use using motorTorque instead of a force on the car's rigid body to see what happens.
     
  7. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    It means nothing. It's arbitrary.

    So, what you need to ask yourself is why is your car's mass 10? Why not 1? I had some crazy issues with car physics until I lowered all of the mass of everything down to < 1. I think my tires were like 0.03 mass and my car body was like 0.3-0.5 and then I got it doing jumps off of hills without rolling over, etc. I experienced weird things with high values on mass and force, like the same simulation ran 10 times would yield 3 different solutions when it was ran. With lower values, I was able to get very consistent behavior without doing anything stupid with center of mass, etc.

    I don't have the old project in front of me, sorry. Are you using the wheels to propel the car? Please tell me you're not using addforce to the car? Please, please tell me you're using this?
     
  8. Claudio-Forain

    Claudio-Forain

    Joined:
    Nov 27, 2014
    Posts:
    4
    As I stated, no, I was using addForce to the car and I will be testing addTorque now. Is addTorque also the way to simulate a better engine to the car?

    About the mass being 0.1 or 10, I find that weird, because in this unity car tutorial (http://u3d.as/content/unity-technologies/car-tutorial/1qU) they explicitly change the mass to "something more realistic like 1400", which make me think that maybe they are basing that values in the international system (KG). But I guess that in the end, it boils down to the proportions between your physics objects rather than absolute numbers.
     
  9. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    I don't know what that tutorial says or who wrote it, I'm only speaking from personal experience. The documentation advises that your largest object should be no more than 100 times the mass of the smallest object, and I got tired of adding 30,000 force to objects just to make them budge.

    Right now there's no reason why your car should drift as the car body is being propelled by magic. If a car had a rocket pushing it, it would act like your current car. Yes, addtorque is essential for car behavior because real cars have wheels that rotate for acceleration, and tires have friction/slip etc.
     
  10. Schumaker

    Schumaker

    Joined:
    Jul 14, 2016
    Posts:
    40
    Hello,
    any tip to make a camera like on this game above?

    thanks
     
  11. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    1) Please don't resurrect an old thread without something of value to add to the topic at hand.
    2) Your question doesn't belong in the board this thread resides (Physics).

    Create a new thread in the appropriate board, and link to the video from there. I promise you'll get better reception that way ;)
     
  12. michealcaj

    michealcaj

    Joined:
    Aug 18, 2017
    Posts:
    191
    Check this out I'm Still working on the drift but gear transmission and wheel balance is just fine.