【发布时间】:2021-09-27 08:13:34
【问题描述】:
如果物体分布不均匀,我有一个可以在宽圆柱上摆动的平台。
为此,我创建了一个带有网格碰撞器的圆柱体,在其顶部放置了一个平台,其中心彼此重合。
然后我在平台上附加了一个代码,冻结了它的位置,即平台现在只能旋转,不能下降。
代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeterminantOfPlatformEquilibrium : MonoBehaviour
{
Vector3 newYPos;
void Start()
{
newYPos = transform.position;
}
void Update()
{
/*We're setting the position of the object in the
"y" direction - unchanged, and equal to zero,
so that the platform does not fall becaude of gravity*/
newYPos.y += 0.0f;
transform.position = newYPos;
newYPos += new Vector3(0f, 0f, 0f);
}
}
除了冻结平台的位置,我还必须冻结它在 y 和 z 方向的旋转,以便它只在一个方向旋转 - 在 x 中。
我尝试使用 Quaternion 类中对 Euler () 方法的调用来执行此操作,将某个旋转角度设置为 x 轴,并将其他 2 个轴设置为零,在我看来,一切都应该工作,但这条线在我的代码中似乎没有做任何事情:Quaternion rotation = Quaternion.Euler(23f, 0f, 0f);
您有更多可能的选项来冻结这两个轴吗?
【问题讨论】:
标签: c# unity3d rotation quaternions euler-angles