動く床とunityちゃんの動きを連動させたくunityちゃんが動く床に載っている間のみ動く床とunityちゃんを親子関係にする方法を試してみました。動く床とunityちゃんは以下のコードで動く床の子になるのですが、unityちゃんが動く床に乗ってる間unityちゃんの体が薄っぺらくなってしまいうまくいきません。動く床には以下のコードをつけて親子関係になるように設定しています。どなたかわかる方いらっしゃいましたら教えてください↓↓以下コード
protected virtual void OnCollisionEnter(Collision other) { if (other.gameObject.CompareTag("Player")) { other.gameObject.transform.SetParent(gameObject.transform); } } protected virtual void OnCollisionExit(Collision other) { if (other.gameObject.CompareTag("Player")) { other.gameObject.transform.SetParent(null); } } ////////////////////////////////////////////////////////////// また動く床は以下のコードを動く床にアタッチして直接動かしています。↓ [SerializeField] protected float moveX = 0; [SerializeField] protected float moveY = 0; [SerializeField] protected float moveZ = 0; [SerializeField] protected float speed = 0; protected float step; protected bool goBack = false; protected Vector3 origin; protected Vector3 destination; protected override void Start() { origin = transform.position; destination = new Vector3(origin.x - moveX, origin.y - moveY, origin.z - moveZ); } protected override void FixedUpdate() { if (stop) { return; } step = speed * Time.deltaTime; if (!goBack) { transform.position = Vector3.MoveTowards(transform.position, destination, step); if (transform.position == destination) { goBack = true; StartCoroutine(WaitTimer()); } } else { transform.position = Vector3.MoveTowards(transform.position, origin, step); if (transform.position == origin) { goBack = false; StartCoroutine(WaitTimer()); } } }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。