2016-10-06 8 views
1
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); 
} 

} 

私はプレイヤーにこのスクリプトを添付した移動作る方法を、バウンスを開始し、壁に当たったとき、すべてのものが正常に動作しているが、それは障害物に当たったとき、それはdoesnのbouncing..butそれが開始されます「T iは平面を用いて粉砕を行ったプレイヤについてキューブプレイヤーが、それはプレイヤーが正常に

を使用して、4つの壁は衝突、剛体を添加し、質量と重力剛体設定されている(壁がヒットされた場合のみ)地面に

バウンス1

壁には、ボックスコライダーと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); 
} 
} 
+0

これはあなたの状況に関連するが、あなたはしたくない場合は、あなたのあなたがそれらのように、剛体の設定を確認する必要があります回転させるように変換しない場合があります値は変更されません。それはx/y/z座標でそれを分けるので、あなたはそれを特定することができます。 –

答えて

1

は、ここにあなたが試すことができますがいくつかある私の新しいコードではこの:

  • が壁
  • からrigidbodyを削除するには、transform.Translateの代わりにrigidBodyコンポーネントを使用してプレーヤーを移動します。ここで

Unity Tutorialからのサンプルコードです:

using UnityEngine; 
using System.Collections; 

public class PlayerController : MonoBehaviour 
{ 
    public float speed; 
    Rigidbody rigidbody; 

    void Start() 
    { 
     rigidbody = GetComponent<Rigidbody>(); 
    } 

    void FixedUpdate() 
    { 
     float moveHorizontal = Input.GetAxis ("Horizontal"); 
     float moveVertical = Input.GetAxis ("Vertical"); 
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); 
     rigidbody.velocity = movement * speed; 
    } 
} 
+0

このスクリプトをプレイヤーに追加すると、プレイヤーはまったく動かない –

+0

@Umair_M私は新しいスクリプトを自分のキューに入れています...回転以外は実際には回転しません。なぜ回転がうまくいかないのですか? –

+0

あなたはQuaternionを使用しています。また、そのw、x、y、z成分は、伝統的なx、y、z回転として使用することはできません。代わりにEulerAnglesを使用してください。ちょうど私の答えのように。 –

関連する問題