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. Dismiss Notice

Annoying little problem that i know has simple solution.

Discussion in 'Scripting' started by RoryScanlan, Aug 19, 2014.

  1. RoryScanlan

    RoryScanlan

    Joined:
    Jan 25, 2014
    Posts:
    139
    Been a while since i coded, im trying to change the stiffness value for my wheel collider but im getting this error
    Here is the code, i know this is a simple fix but im just having a durrrr moment, any help please? :)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TireTraction : MonoBehaviour {
    5.  
    6.     public GameObject Wheel;
    7.     public float ConcreteSideWaysFriction;
    8.     private WheelCollider wheelCollider;
    9.     private WheelHit floor;
    10.  
    11.  
    12.     void Start()
    13.     {
    14.         wheelCollider = Wheel.GetComponent<WheelCollider> ();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         wheelCollider.GetGroundHit (out floor);
    20.         if (floor.collider.tag == "Terrain")
    21.         {
    22.             wheelCollider.sidewaysFriction.stiffness = ConcreteSideWaysFriction;
    23.         }
    24.  
    25.     }
    26. }
    27.  
     
    Last edited: Aug 19, 2014
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Like it says; store the filthy slut:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TireTraction : MonoBehaviour {
    5.  
    6.     public GameObject Wheel;
    7.     public float ConcreteSideWaysFriction;
    8.     private WheelCollider wheelCollider;
    9.     private WheelHit floor;
    10.  
    11.  
    12.     void Start() {
    13.         wheelCollider = Wheel.GetComponent<WheelCollider> ();
    14.     }
    15.  
    16.     WheelFrictionCurve storedCurve; //stored curve
    17.  
    18.     void Update()
    19.     {
    20.         wheelCollider.GetGroundHit (out floor);
    21.         if (floor.collider.tag == "Terrain") {
    22.             storedCurve.stiffness = ConcreteSideWaysFriction; //set your friction
    23.             wheelCollider.sidewaysFriction = storedCurve; //apply the curve
    24.         }
    25.     }
    26. }
     
    RoryScanlan likes this.
  3. RoryScanlan

    RoryScanlan

    Joined:
    Jan 25, 2014
    Posts:
    139
    Thanks man, with my very limited scripting i sometimes stuggle to understand the errors :)
    To be honest i still dont understand how making a seperate copy of the WheelFrictionCurve helps, but thanks again!

    *Edit*
    Oh I think i Just relised... We are copying the whole curve.. edit a small part, then reapplying the entire curve?
    *Edit*
     
  4. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    No worries; that's what we're here for :) Errors are always intimidating when you start out, they get better though :) it's when things don't work and errors don't appear, thats when things get interesting ;)

    yeah pretty much, well we're not actually copying the curve. But we're creating a new one. Then modifying it's stiffness and applying.