前提・実現したいこと
以下の画像のような、ボールを跳ね返すゲームを制作しています。
車とボールを跳ね返す台は別々のオブジェクトで、それぞれにRigidBodyを適用するために親子にしていません。
RigidBodyを台に適用しているのは、台がスクリプトによって上下に動き、その動きをボールの跳ね返しに影響させるためです。
また、台は車の移動を追従して動きます。
発生している問題
車が動くと台が少し遅れて追従されます。
このずれを改善したいです。
該当のソースコード
cs
1using UnityEngine; 2 3public class Mover : MonoBehaviour 4{ 5 private Rigidbody rb; 6 public float speed; 7 void Start() 8 { 9 rb = GetComponent<Rigidbody>(); 10 } 11 void FixedUpdate() 12 { 13 rb.MovePosition(transform.position + transform.forward * Input.GetAxis("move") * Time.fixedDeltaTime * speed); 14 } 15 16} 17
cs
1using UnityEngine; 2 3public class Stretcher : MonoBehaviour 4{ 5 public float start; 6 public float end; 7 public float upSpeed; 8 public float downSpeed; 9 public string key; 10 public float pos; 11 private Rigidbody rb; 12 private bool move; 13 void Start() 14 { 15 rb = GetComponent<Rigidbody>(); 16 pos = start; 17 } 18 void Update() 19 { 20 if (Input.GetKey(key)) 21 { 22 move = true; 23 } 24 else 25 { 26 move = false; 27 } 28 } 29 30 void FixedUpdate() 31 { 32 if (move) 33 { 34 pos += upSpeed * Time.fixedDeltaTime; 35 } 36 else 37 { 38 pos -= downSpeed * Time.fixedDeltaTime; 39 } 40 if(pos < start) 41 { 42 pos = start; 43 } 44 if (pos > end) 45 { 46 pos = end; 47 } 48 49 rb.MovePosition(car.transform.position + transform.up * pos); 50 } 51} 52
試したこと
「スクリプト実行順序」の設定を以下の画像のようにしましたが効果はありませんでした。
補足情報
Unityのバージョン: 2018.4.23f1
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/10 12:30
2020/11/10 13:21
2020/11/10 13:22