ฉันกำลังพยายามสร้างเครื่องจำลองรถแบบง่ายๆ และเมื่อฉันใช้การTransform.Rotate() เพื่อหมุนคำนำของล้อ (แกน x) และการใช้การTransform.localEulerAngles() เพื่อหมุนในทิศทางการหมุน (แกน y) เท่านั้น localEulerAngles() ใช้งานได้ เมื่อฉันใช้วิธีเดียว การหมุนคำนำวงล้อ (แกน x) ก็ใช้ได้ แต่ฉันไม่สามารถทำให้ทั้งสองวิธีทำงานได้ คุณมีแนวคิดในการทำให้พวกเขาทำงานร่วมกันได้อย่างไร?
float ro = 20f; // 20 degrees turn
//to preserve the x and z values of rotation
Vector3 rot = wheel.gameObject.transform.rotation.eulerAngles;
//rotates the wheels angle
wheel.gameObject.transform.localEulerAngles = new Vector3(rot.x, ro, rot.z);
float vel = wheel.rpm * 2 * Mathf.PI / 60 * Time.deltaTime * Mathf.Rad2Deg;
//rotates the wheels forward
wheel.gameObject.transform.Rotate(vel, 0, 0);