发布于 2021-11-22 20:23:32
首先,我会停止改变自行车的重心。
然后,我会用自行车来计算扭矩来应用。评论中的解释:
float adjustFactor = 0.5f; // this value requires tuning
// physics actions should occur in FixedUpdate in most cases
void FixedUpdate()
{
// project the bike's local up to the plane perpendicular to the bike's forward
Vector3 projectedUp = transform.up - Vector3.Dot(transform.forward, _transform.up);
// find the angle from that projection to global up, around bike forward
float upOffset = Vector3.SignedAngle(projectedUp, Vector3.up, transform.forward);
// use angle difference to calculate an adjustment
float adjustment = upOffset * adjustFactor;
// maybe do something else like adjustment = log(adjustment) or adjustment^2
// to change easing of adjustment force. Requires some trial and error
// and further tuning of adjustFactor.
// Apply adjustment as vector around rb's forward
_rigidbody.AddRelativeTorque(new Vector3(0f, 0f, adjustment));
}相关答案:利用扭矩稳定气垫船刚体直立
https://stackoverflow.com/questions/70054613
复制相似问题