Search Unity

Move and Turn a box (Kart Physics)

Discussion in 'Scripting' started by Cyril5, Oct 7, 2015.

  1. Cyril5

    Cyril5

    Joined:
    May 6, 2013
    Posts:
    6
    Hello, :)

    I'm French and I'm making a kart game system like mario kart or Crash Team Racing.
    I tried to make a car with Weel Colliders but it wasn't work :(
    so I decided to use a box collider and move it with Rigidbody.AddForce and turn on y axis with Rigidbody.AddTorque :

    Code (CSharp):
    1. Awake() {
    2.     rb = GetComponent<Rigidbody>();
    3. }
    4.  
    5. FixedUpdate() {
    6.      rb.AddForce(transform.forward * power * Input.GetAxis("Vertical");
    7.      rb.AddTorque(Vector3.up * turnSpeed * Input.GetAxis("Horizontal");
    8. }

    Unfortunately the box slip too much and decelerate very quickly when vertical axis is released
    How I can fix it ? to get a box with like car movement ?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    What you need is more friction along the X axis and less friction along the Z axis. This is, really, the exact purpose of the wheel collider, and I'm not aware of a way to fake it in a box collider. I'd suggest you give those another shot.
     
  3. Cyril5

    Cyril5

    Joined:
    May 6, 2013
    Posts:
    6
    What do you propose ? Do you have a idea to make a kart ?
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
  5. Cyril5

    Cyril5

    Joined:
    May 6, 2013
    Posts:
    6
    Yes and I add centerOfMass & AntiRollBar script, I got a stable car but very slippery (not easy to control)
    I don't understood why
     
  6. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Did you try increasing the Wheel Collider's sideways friction stiffness?
     
  7. Cyril5

    Cyril5

    Joined:
    May 6, 2013
    Posts:
    6
  8. Cyril5

    Cyril5

    Joined:
    May 6, 2013
    Posts:
    6
    But I want to know how to make a arcade car like in SuperTuxKart, Mario kart, CTR... by using Wheels Colliders.
    I would like to get a driving system work with Toon Car (stable, fast, not very slippery, simple collisions and curved road).

    What I need to done it ? any suggestions ?

    Please :)
     
    Last edited: Nov 2, 2015