【发布时间】:2014-08-18 07:16:14
【问题描述】:
我想做一个像神庙逃亡这样的游戏。我需要根据设备倾斜的程度来旋转播放器的平台。我正在尝试加速计,但我无法让游戏对象倾斜。 请指导我。 谢谢
这是我以前在 cmets 中使用代码的代码,现在我正在尝试使用 cmets 中的代码
public class tilt : MonoBehaviour {
Vector3 dir;
float movespeed;
bool istilt;
// Use this for initialization
void Start () {
dir=Vector3.zero;
movespeed=10.0f;
istilt=true;
}
// Update is called once per frame
void FixedUpdate()
{
//dir.x=-Input.acceleration.y;
//transform.Translate(dir.x,0,0);
//transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
//Vector3 vec = Physics.gravity;
/*vec.x = -Physics.gravity.z;
vec.z = Physics.gravity.x;
vec.y = 0;
transform.rotation = Quaternion.Euler(vec);*/
/*movespeed=-Input.acceleration.y;
transform.Rotate(Vector3.up*movespeed*5.0f);
*/float zmovment = Input.GetAxis("Horizontal");//-Input.acceleration.y;
float xmovment = Input.GetAxis("Vertical");//-Input.acceleration.x;
Vector3 dir = new Vector3(xmovment,0,zmovment);
Vector3 tgravity =new Vector3(zmovment*2.0f,-15,xmovment*2.0f);
Physics.gravity= tgravity;//new Vector3(zmovment*speed,gravity,xmovment*speed);
Vector3 vec = Physics.gravity;
vec.x = -Physics.gravity.z;
vec.z = Physics.gravity.x;
vec.y = 0;
transform.rotation = Quaternion.Euler(vec);
}
}
【问题讨论】:
标签: unity3d accelerometer