转半径值长

时间:2016-11-18 21:16:20

标签: c# math unity3d

这段代码应该使用它的速度和角速度绘制一条代表物体转弯半径的直线。但是,出于某种原因,给出的半径比它应该的长得多:

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 个答案:

答案 0 :(得分:1)

根据enter image description here,Unity的角速度已经是每秒弧度,但你乘以Mathf.Deg2Rad,所以只需删除它并将行读成:{{1} }。