[英]Rotate GameObject on z degrees around the y axis
我有一個游戲對象,該對象圍繞z軸傾斜x度,並圍繞x軸傾斜z度。 我設法使用以下代碼做到這一點
public float xtilt, ztilt, ytilt;
//These virables are public float values for how much tilt or rotation I want.
//xtilt for how much rotation when moving on the x axis.
//ztilt for how much rotation when moving on the z axis.
//ytilt for how much rotation when moving on the y axis.
void FixedUpdate()
{
Rigidbody rb;
rb.rotation = Quaternion.Euler(rb.velocity.z * ztilt, 0.0f, rb.velocity.x * -xtilt);
}
上面的代碼給了我以下內容
目標:
我要添加:圍繞y軸旋轉或傾斜游戲對象x度。
因此它將是這樣的:
我試圖遍歷代碼來實現這一目標,但是沒有運氣。
有任何想法嗎??
假設ztilt * rb.velocity.z = z degrees
。
如果您想使用zdegrees繞Y軸旋轉對象,那不應該取代Y參數嗎? 像這樣:
rb.rotation = Quaternion.Euler(0f, rb.velocity.z * ztilt, 0f);
從unity文檔中,euler函數的聲明為:
public static Quaternion Euler(float x, float y, float z);
如果需要z度,請使用包含z值的變量:
更換
rb.velocity.y * ytilt
通過
rb.velocity.y * ztilt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.