【发布时间】:2017-08-15 00:06:13
【问题描述】:
首先,我想明确一点,这不是这个问题的重复:unity 3d rotate the gameobject according to accelerometer
所以,我设法通过使用加速度计和指南针统一旋转了一个对象。这正常工作,但是当另一个对象与它碰撞时,它会穿过对象,导致对象随机移动。
我意识到这是因为我直接改变了对象的变换。我知道我不应该直接修改变换,而应该使用刚体,但是,我不知道如何将其更改为不直接改变变换的位置。
这是我当前旋转对象的方式:
float norm=0f;
Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
Input.compass.enabled = true;
if (norm == 0) {
norm = Input.compass.trueHeading;
}
float val=Input.compass.trueHeading-norm;
transform.rotation=Quaternion.Euler( new Vector3 ( (Input.acceleration.y-1)*90,val ,0));
transform.Rotate (Input.acceleration.x*90*transform.forward);
}
那么我怎样才能改变它,这样我就不会直接改变变换呢?
提前致谢!
【问题讨论】:
标签: c# unity3d accelerometer collision rigid-bodies