首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能统一平衡摩托车

不能统一平衡摩托车
EN

Stack Overflow用户
提问于 2021-11-21 12:40:57
回答 1查看 294关注 0票数 0

我想平衡摩托车和统一物理。我们可以通过在z轴上冻结旋转来平衡平衡自行车,但这似乎不是很好的.So,我尝试了.This方法平衡自行车很少几秒钟,但出于某种原因,自行车开始在空中跳跃,或有时翻转.I是开放的任何建议。我已经做了一些2d的非物理游戏,但统一物理学是我的新的。在这里输入图像描述

在这里输入图像描述

在这里输入图像描述

EN

回答 1

Stack Overflow用户

发布于 2021-11-22 20:23:32

首先,我会停止改变自行车的重心。

然后,我会用自行车来计算扭矩来应用。评论中的解释:

代码语言:javascript
复制
​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));
}

相关答案:利用扭矩稳定气垫船刚体直立

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70054613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档