【发布时间】:2017-06-05 09:51:39
【问题描述】:
我有一个横向的 Unity 游戏。我希望能够向左和向右旋转相机。更多,我想根据陀螺仪在y轴的倾斜,以及左右旋转的总矢量来前后移动相机。换句话说,我希望能够像在房间里行走的人一样移动相机。相机是我游戏的主要参与者。
这是我尝试做的:
GameObject CamParent;
Rigidbody RB;
void Start()
{
CamParent = new GameObject("CamParent");
CamParent.transform.position = this.transform.position;
this.transform.parent = CamParent.transform;
Input.gyro.enabled = true;
RB = this.GetComponent<Rigidbody>();
}
void Update()
{
CamParent.transform.Rotate(0, -Input.gyro.rotationRateUnbiased.y, 0);
this.transform.Rotate(-Input.gyro.rotationRateUnbiased.x, 0,0);
float Z = -Input.gyro.userAcceleration.z;
RB.AddForce(new Vector3(0,0,Z)*10);
}
【问题讨论】:
-
我不确定我是否理解您想要做什么,但是将刚体添加到相机父级并添加力而不是添加直接给相机强行?否则随着相机从其原始位置移动,旋转相机父级的效果会发生变化。