i have basic car model. far have managed wheels rotating in 1 of 2 ways:
- the wheel rotates on local z axis when turns
- the wheel rotates on local y axis when drives forward or backward
they both work fine, cannot them both work @ same time. absolutely stumped , starting piss me off! have been trying follow video (https://www.youtube.com/watch?v=0jvj2fmvbbs) , have following error:
- cannot modify value type return of 'unityengine.transform.rotation'. consider storing value in temporary variable.
could take @ code , show me i'm doing wrong? in advance.
code:
public wheels[] wheel; public float enginepower = 20f; public float turnpower = 20f; void fixedupdate () { float torque = input.getaxis("vertical") * enginepower; float turnspeed = input.getaxis("horizontal") * turnpower; //4 wheel drive wheel[0].move(torque); wheel[1].move(torque); wheel[2].move(torque); wheel[3].move(torque); //front wheel steering wheel[0].turn(turnspeed); wheel[1].turn(turnspeed); } void update () { wheel[0].transform.rotate(0, 0, wheel[0].getcomponent<wheelcollider>().rpm / 60 * 360 * time.deltatime); //only 1 wheel shown simplicity wheel[0].transform.rotation.y = wheel[0].getcomponent<wheelcollider>().steerangle - wheel[0].transform.rotation.z; }
the "rotation" variable of transform quaternion
trying in second line of code in update break rotation. instead, you'll have use transform.rotate
again , access z value of rotation transform's local euler angles.
wheel[0].transform.rotate(0, wheel[0].getcomponent<wheelcollider>().steerangle - wheel[0].transform.localeulerangles.z, 0);
Comments
Post a Comment