【问题标题】:How to Hold position on cylinder/pendulum using unity3d如何使用unity3d在圆柱体/摆锤上保持位置
【发布时间】:2015-08-13 16:47:14
【问题描述】:

我是 Unity 的新手,我正在尝试创建一个像刚性钟摆一样移动的圆柱体。我在气缸顶部使用铰链接头和电机来增加力量。

当我停止施力时,如何让气缸保持位置而不回落到“死”位置?

JointMotor m = new JointMotor();
m.force = 10000;
m.targetVelocity = 0;
m.freeSpin = true;
GetComponent<HingeJoint>().motor = m;

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您可以尝试手动计算。 创建一个空对象作为枢轴,将 arm 和 bob 设为子对象并使用 Lerp() 旋转您的枢轴。这样的事情可能会起作用:

    public class Penduluum : MonoBehaviour {
     public float angle = 45.0f;
     public float speed = 1.5f;
    
     Quaternion Start, End;
    
     void Start () {
         Start = Quaternion.AngleAxis ( angle, Vector3.forward);
         End   = Quaternion.AngleAxis (-angle, Vector3.forward);
     }
    
     void Update () {
       transform.rotation = Quaternion.Lerp (Start, End, (Mathf.Sin(Time.time * speed) + 1.0f) / 2.0f);
     }
    

    }

    【讨论】:

      猜你喜欢
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多