ゲームを開始したら指定の位置(x, y, z) = (0f, 0f, 0f)まで進んで止まるという命令を書きたいのですが(画像1参照)、真っ直ぐ進まず何故かy軸方向にも移動してしまいます(画像2参照)。(画面端で止まっているのは他のスクリプトで移動範囲を制限しているからです)
何かヒントを頂きたいです。また、ほかにもスクリプトで間違っているところがあれば教えてほしいです。
C#
1public class FirstMovement : MonoBehaviour 2{ 3 private float speed = 800f; 4 private Vector3 destination; 5 private bool arrived; 6 7 // Start is called before the first frame update 8 void Start() 9 { 10 arrived = false; 11 destination = new Vector3(0f, 0f, 0f); 12 13 Rigidbody PlayerRb = this.gameObject.GetComponent<Rigidbody>(); 14 PlayerRb.AddForce(transform.forward * speed); 15 16 if (Vector3.Distance(transform.position, destination) < 0.5f) 17 { 18 arrived = true; 19 speed = 0f; 20 } 21 } 22}

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/20 15:03
2021/08/20 16:40