Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Wheel Collider Stifness Factor dissapears after I Build

Discussion in 'Editor & General Support' started by Tabu, Jun 5, 2010.

  1. Tabu

    Tabu

    Joined:
    Dec 3, 2008
    Posts:
    44
    Im making this small racing game for my kids, and are just about done, I tweaked the wheels so the cars are easy to drive, they work in editor..but as soon as I build the game, everything seems to change? And the cars don't slide anymore? Have I missed something, or is the wheel collider Pro exclusive or something?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the code you are using to control the WheelColliders?
     
  3. Tabu

    Tabu

    Joined:
    Dec 3, 2008
    Posts:
    44
    I have been thinking about posting the code, but I guess I was a bit to shy, since I don't feel confident with what Im dooing, I might show some embarresing sollutions.. but I guess, asking for help and look stupid for 5 minutes, is better than not asking and be stupid for life?

    I have set the wheelcolliders to have a radius of 1 a Suspension distance of 3 and a spring of 5, to help keeing it on its the right way up. Then my forward friction stiffness is set to 0,5 and my sideways friction stiffness is set to 0,3.

    Do you know if there is any way to set the Stiffness Factor from script? I have tried adding different kinds of values to Wheel1.sidewaysFriction.stiffness but it wont take float(any) values.

    This is a real pain for me, since it works just fine in the editor, but as soon as I Build the project.. it stops working and behaves completely different.

    Thanks a bunch for your time!

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. public class Car01Ctrl : MonoBehaviour {
    6.  
    7.     // Setting up the car
    8.     public WheelCollider Wheel1;
    9.     public WheelCollider Wheel2;
    10.     public WheelCollider Wheel3;
    11.     public WheelCollider Wheel4;
    12.     public int carSpeed = 20;
    13.     public Rigidbody carRigid;
    14.  
    15.     // Variables used to look for controlpoints
    16.     public Collider ControlPoint1;
    17.     public Collider ControlPoint2;
    18.     public Collider ControlPoint3;
    19.     public Collider ControlPoint4;
    20.     public Collider GoalPoint;
    21.     public int getRounds = 2;
    22.     public static int rounds = 2; // Static makes it so that this can be used in GoalScript, and updates.
    23.     int ctrlCounter = 0;
    24.    
    25.     //Speed Calculation code is put here.
    26.     Vector3 point;
    27.     public static float car1TransferSpeed;
    28.  
    29.     //To get the position of the car
    30.     Vector3 getCar1Position;
    31.  
    32.  
    33.     // Use this for initialization
    34.     void Start () {
    35.         carRigid.centerOfMass = new Vector3(0,0,0);
    36.        
    37.         rounds = getRounds; // Keep track og how many rounds the car has done.
    38.        
    39.         getCar1Position = carRigid.position; // Get the Vector3 position of the car.
    40.      }
    41.    
    42.     // Update is called once per frame
    43.     void Update () {
    44.  
    45.         carRigid.AddForce(new Vector3(0, -9000, 0));
    46.  
    47.         // This control the forward/backward movement of the car.
    48.         if (Input.GetButton("Vertical"))
    49.         {
    50.             var verDirection = Input.GetAxis("Vertical");
    51.             // spin the wheel forward
    52.            
    53.             Wheel1.motorTorque = carSpeed * verDirection;
    54.             Wheel2.motorTorque = carSpeed * verDirection;
    55.             Wheel3.motorTorque = carSpeed * verDirection;
    56.             Wheel4.motorTorque = carSpeed * verDirection;
    57.    
    58.         }
    59.        
    60.         // This control the forward/backward movement of the car.
    61.         if (Input.GetButtonUp("Vertical"))
    62.         {
    63.             // spin the wheel forward
    64.  
    65.             Wheel1.motorTorque = 0;
    66.             Wheel2.motorTorque = 0;
    67.             Wheel3.motorTorque = 0;
    68.             Wheel4.motorTorque = 0;
    69.  //           Debug.Log("Spped 0");
    70.         }
    71.         if (Input.GetButton("Horizontal"))
    72.         {
    73.             var rotDirection = Input.GetAxis("Horizontal");
    74.  
    75.             // steer forwards
    76.             Wheel1.steerAngle = 35 * rotDirection;
    77.             Wheel2.steerAngle = 35 * rotDirection;
    78.             Wheel3.steerAngle = 0;
    79.             Wheel4.steerAngle = 0;
    80.  
    81.         //  Debug.Log("ButtonDown");
    82.         }
    83.  
    84.  
    85.         if (Input.GetButtonUp("Horizontal"))
    86.         {
    87.             // steer forwards
    88.             Wheel1.steerAngle = 0;
    89.             Wheel2.steerAngle = 0;
    90.             Wheel3.steerAngle = 0;
    91.             Wheel4.steerAngle = 0;
    92.  
    93.         //  Debug.Log("ButtonUp");
    94.         }
    95.  
    96.         //Code to calculate speed goes here.
    97.         Vector3 car1Speed = rigidbody.GetRelativePointVelocity(point);
    98.        
    99.         car1TransferSpeed = car1Speed.magnitude;
    100.     }
    101.  
    102.     //Keeps track of if the car is getting all the way around.
    103.     void OnTriggerEnter(Collider Other)
    104.     {
    105.         if (Other == ControlPoint1  ctrlCounter == 0)
    106.         {
    107.             ctrlCounter = 1;
    108.             Debug.Log("Controlpoint1");
    109.         }
    110.  
    111.         if (Other == ControlPoint2  ctrlCounter == 1)
    112.         {
    113.             ctrlCounter = 2;
    114.             Debug.Log("Controlpoint2");
    115.         }
    116.  
    117.         if (Other == ControlPoint3  ctrlCounter == 2)
    118.         {
    119.             ctrlCounter = 3;
    120.             Debug.Log("Controlpoint3");
    121.         }
    122.  
    123.         if (Other == ControlPoint4  ctrlCounter == 3)
    124.         {
    125.             ctrlCounter = 4;
    126.             Debug.Log("Controlpoint4");
    127.         }
    128.  
    129.         if (Other == GoalPoint  ctrlCounter == 4)
    130.         {
    131.             ctrlCounter = 0;
    132.             rounds--;
    133.  
    134. //            Debug.Log("There is " + rounds + " left");
    135.         }
    136.     }
    137. }
    138.  
     
  4. Tabu

    Tabu

    Joined:
    Dec 3, 2008
    Posts:
    44
    For some odd reason it now works..?!? Or it now dosent work.. but it shows the same behaviour in the editor as it does after being build, which mean that I could tweak it once again (Stiffness is now 0.03, and speed was set lower) Moving the project between computers seemed to make it behave! However, I cannot recreate the issue :( So no bug rapport from me