Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

WheelColliders stiffness and c#

Discussion in 'Scripting' started by Sandoze, Dec 19, 2008.

  1. Sandoze

    Sandoze

    Joined:
    Oct 4, 2008
    Posts:
    19
    I'm trying to modify the stiffness of my wheel(s) so I can remove friction from them when needed.

    Code (csharp):
    1.  
    2.     private void removeWheelFriction(){
    3.         foreach(WheelCollider wheel in wheels){
    4.            
    5.             WheelFrictionCurve sf = wheel.sidewaysFriction;
    6.             WheelFrictionCurve ff = wheel.forwardFriction;
    7.             ff.stiffness = 0;
    8.             sf.stiffness = 0;
    9.             print("wheel"+wheel.sidewaysFriction.stiffness);
    10.         }
    11.     }
    12.  
    Does not actually change the stiffness... it still comes through as the default value of 1.

    doing:
    Code (csharp):
    1.  
    2. wheel.forwardFriction.stiffness = 0
    3.  
    returns and error that I cannot modify the return value because it is not a variable.

    How do I get this to work in c#?[/quote]
     
    Mashti likes this.
  2. Sandoze

    Sandoze

    Joined:
    Oct 4, 2008
    Posts:
    19
    Never mind... I thought I had tried this already.. but this works:

    Code (csharp):
    1.  
    2.     private void removeWheelFriction(){
    3.         foreach(WheelCollider wheel in wheels){        
    4.             WheelFrictionCurve sf = wheel.sidewaysFriction;
    5.             WheelFrictionCurve ff = wheel.forwardFriction;
    6.             ff.stiffness = 0;
    7.             sf.stiffness = 0;
    8.             wheel.forwardFriction = ff;
    9.             wheel.sidewaysFriction = sf;
    10.             print("wheel"+wheel.sidewaysFriction.stiffness);
    11.         }
    12.     }
    13.  
     
unityunity