前提・実現したいこと
Unityで移動するものをつくりたいです
→
で右回転
←
で左回転
↑
で前進
↓
で後退
Space
でジャンプ
###付いているコンポーネント
Cube
(地面):Transform, Cube(Mesh Fliter), Mesh Render, Box Collider, New Material
i
(動くもの):Transform, Rigidbody, Box Collider, MyObject(Script)
発生している問題・エラーメッセージ
AddForce
がうまくいきません
前進・後退・ジャンプができません
どなたか教えてください
お願いします
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4public class MyObject : MonoBehaviour 5{ 6 private Rigidbody RB; 7 8 void Start() 9 { 10 RB = GetComponent<Rigidbody>(); 11 12 } 13 14 void Update() 15 { 16 if (Input.GetKey(KeyCode.RightArrow)) 17 { 18 transform.Rotate(new Vector3(0, 1, 0)); 19 } 20 21 if (Input.GetKey(KeyCode.LeftArrow)) 22 { 23 transform.Rotate(new Vector3(0, -1, 0)); 24 } 25 26 if (Input.GetKey(KeyCode.UpArrow)) 27 { 28 RB.AddForce(new Vector3(0, 0, 5)); 29 } 30 31 if (Input.GetKey(KeyCode.DownArrow)) 32 { 33 RB.AddForce(new Vector3(0, 0, -5)); 34 } 35 } 36 void OnCollisionStay(Collision col) 37 { 38 if (Input.GetKey(KeyCode.Space)) 39 { 40 RB.AddForce(new Vector3(0, 5, 0)); 41 } 42 43
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/13 03:16