2016-11-18 85 views
0

這段代碼應該用它的速度和角速度繪製一條代表物體轉彎半徑的直線。出於某種原因,雖然給出的半徑是很長的,它應該是:轉彎半徑值長

AngularVel = m_Rigidbody.angularVelocity.y; 
Vel = m_Rigidbody.velocity.magnitude; 
//Vel = transform.InverseTransformDirection(m_Rigidbody.velocity).z; same result 
float radius = Vel/(AngularVel * Mathf.Deg2Rad); 
Quaternion RadiusDirQuat = Quaternion.AngleAxis(m_Rigidbody.rotation.eulerAngles.y + 90, Vector3.up); 
Vector3 radiusDir = RadiusDirQuat * Vector3.forward; 
Debug.DrawRay(m_Rigidbody.position + Vector3.up, radiusDir * radius, new Color(1, 0, 0.5f, 1)); 

我用這篇文章供參考:https://revisionmaths.com/advanced-level-maths-revision/mechanics/motion-circle

+1

我想你想'AngularVel = m_Rigidbody.angularVelocity.magnitude',不是嗎? – Quantic

+0

也許你在float float = ... line的某個地方忘了2 * pi。你得到的半徑是原來的6.28倍嗎? angularVelocity.y應該給出每秒旋轉的角速度爲(1 /(2 * pi))倍。如果它每秒有2轉,比每秒4 * pi弧度。 –

+0

@Quantic我用它取代了它,但得到了相同的結果。 –

回答

1

this,Unity的角速度已經弧度每秒,但你乘以Mathf.Deg2Rad,所以只要刪除,並使行讀:float radius = Vel/AngularVel