如何在 Unity 中使用力校正 angular 加速度

How to correct angular acceleration using forces in Unity

我正在开发一款 space 游戏,它需要一些真实的物理特性,例如 space 中的轨道和动量守恒,问题是,我无法开发识别代码angular 物体在 space 中的加速度并使用动量力对其进行校正。

这是我为稳定旋转而编写的函数:

    void RCS_Stabilize()
    {
        Vector3 localangularvelocity = transform.InverseTransformDirection(rigidBody.angularVelocity);
        Debug.Log(localangularvelocity);

        if (!isRCSinUse)
        {
            if (localangularvelocity.x < RCSthreshole)
            {
                RCS_Pitch(1);
            }
            else if (localangularvelocity.x > -RCSthreshole)
            {
                RCS_Pitch(-1);
        }
              // after that i do the same for y and z

这是 RCS_Pitch 函数:

    void RCS_Pitch(int direction)
    {
        rigidBody.AddRelativeTorque(new Vector3(direction * RCSPower, 0, 0));

        if (direction == 1) // Just show the smoke effect
        {
            RCSeffect[0].startSpeed = 1f;
            RCSeffect[3].startSpeed = 1f;
        }
        else
        {
            RCSeffect[1].startSpeed = 1f;
            RCSeffect[2].startSpeed = 1f;
        }
    }

这些函数有点用,但基本上每帧都会调用它们,导致烟雾效果每帧都打开,有时会闪烁。

问题似乎在于您没有在不使用时重置 ParticleSystems 的 startSpeed。

尝试在 RCS_Stabilize 函数的开头添加以下代码:

foreach (var rcsEffect in RCSEffect) {
  rcsEffect.startSpeed = 0f;
}

或者更好的是,为了让它看起来更自然一点,尝试在那里添加衰减。使用 RCS 推进器将使粒子速度最大化,并且在不使用推进器时它会迅速衰减:

foreach (var rcsEffect in RCSEffect) {
  // adjust the 0.3f lerp factor yourself
  rcsEffect.startSpeed = Mathf.Lerp(rcsEffect.startSpeed, 0f, 0.3f);
}