unity3d - Rotation of wheels of a car in unity 5 -


what wanted rotate wheels of car model when run game tiers rotating round car in circular motion can see in picture. script "carcontroller" using attached car , wheel collides , wheels added , tis script written below

   using unityengine;    using system.collections;  public class carcontroller : monobehaviour {  public wheelcollider tirefr;  public wheelcollider tirefl;  public wheelcollider tirerr;  public wheelcollider tirerl;  public float maxspeed = 100;  public float angle = 10;  public transform centerofgravity;  public transform tiretransformfr;  public transform tiretransformfl;  public transform tiretransformrr;  public transform tiretransformrl;  rigidbody rb;  public void applylocalpositiontovisuals(wheelcollider collider)  {      if (collider.transform.childcount == 0)      {          return;      }       transform visualwheel = collider.transform.getchild(0);      vector3 position;      quaternion rotation;      collider.getworldpose(out position, out rotation);      visualwheel.transform.position = position;      visualwheel.transform.rotation = rotation;  }  // use initialization  void start () {      rb = getcomponent<rigidbody>();      rb.centerofmass = centerofgravity.localposition;              }  void update()  {      tiretransformfl.rotate ( tirefl.rpm / 60 * 360 * time.deltatime, 0, 0);      tiretransformfr.rotate ( tirefr.rpm / 60 * 360 * time.deltatime,0,0);      tiretransformrl.rotate ( tirerl.rpm / 60 * 360 * time.deltatime, 0, 0);      tiretransformrr.rotate ( tirerr.rpm / 60 * 360 * time.deltatime, 0, 0);   }                       // update called once per frame  void fixedupdate () {       tirerr.motortorque = maxspeed * input.getaxis("vertical");      tirerl.motortorque = maxspeed * input.getaxis("vertical");      tirefl.steerangle = angle * input.getaxis("horizontal");      tirefr.steerangle = angle * input.getaxis("horizontal");      applylocalpositiontovisuals(tirefl);      applylocalpositiontovisuals(tirefr);      applylocalpositiontovisuals(tirerl);      applylocalpositiontovisuals(tirerr);  }    } 

wheel not rotating properly

i think should ensure: around axis want rotate of wheels?

could provide more screenshots or short movie?


Comments