using UnityEngine;
using System.Collections;
public class Accelerometer : MonoBehaviour {
public Vector3 positionplayer;
// Update is called once per frame
void Update()
{
transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
transform.Rotate (0,0,0);
}
}
我重視這個腳本的球員,每一件事工作正常,但是當它撞到障礙物啓動bouncing..but它不「T使用利用立方體當玩家在牆上它開始反彈擊中,如何讓正確的球員招
對於播放器平面和四個壁已經添加了對撞機,剛體和剛體設置爲與質量重力上我已接地的接地(只有當壁被擊中)
反彈1
爲牆壁我添加了箱子collider和j UST一個剛體
這在我的新代碼
using UnityEngine;
using System.Collections;
public class Accelerometer : MonoBehaviour {
public Vector3 positionplayer;
Rigidbody b;
public float speed = 10.0f;
private Quaternion localRotation;
// Use this for initialization
void Start() {
localRotation = transform.rotation;
}
// Update is called once per frame
void Update()
{
float curSpeed = Time.deltaTime * speed;
//transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
transform.position += (transform.right * Input.acceleration.x) * curSpeed;
transform.position += (transform.forward * -Input.acceleration.z) * curSpeed;
//transform.Rotate (Input.acceleration.x,0,0);
localRotation.z += -Input.acceleration.z * curSpeed;
localRotation.z += Input.acceleration.z * curSpeed;
//transform.rotation = localRotation;
print (transform.position);
}
}
這可能不是有關您的情況,但如果你不想讓你的變換旋轉,你應該在剛體檢查設置,使那些值不會改變。它用x/y/z座標分隔它,所以你可以對它有特異性。 –