我有一个游戏物体,在z轴周围倾斜x度,x轴周围有z度。我使用以下代码成功地做到了这一点
public float xtilt, ztilt, ytilt;
//These virables are public float values for how much tilt or rotation I want.
//xtilt for how much rotation when moving on the x axis.
//ztilt for how much rotation when moving on the z axis.
//ytilt for how much rotation when moving on the y axis.
void FixedUpdate()
{
Rigidbody rb;
rb.rotation = Quaternion.Euler(rb.velocity.z * ztilt, 0.0f, rb.velocity.x * -xtilt);
}上面的代码给了我以下信息
目标:
我想补充一句:围绕y轴旋转或倾斜游戏物体x度。
所以会是这样:
我试图绕过代码来实现这一点,但没有运气。
有什么主意吗?
发布于 2017-12-19 07:52:02
假设ztilt * rb.velocity.z = z degrees。
如果你想用Z度旋转物体绕Y轴旋转,这不应该取代Y参数吗?就像这样:
rb.rotation = Quaternion.Euler(0f, rb.velocity.z * ztilt, 0f);从统一文档中,对euler函数的声明是:
public static Quaternion Euler(float x, float y, float z); 发布于 2017-12-19 08:41:32
如果您想要z度,那么使用包含z值的变量:
替换
rb.velocity.y * ytilt通过
rb.velocity.y * ztilthttps://stackoverflow.com/questions/47881125
复制相似问题