유니티 3d에서 계층구조를 이용해 물체가 회전하면서 이동하는 코드를 짜고 싶습니다.

using System.Collections;using System.Collections.Generic;using UnityEngine;public class GameObject : MonoBehaviour{ void Update() { float speed = 10f; float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); Vector3 dir = new Vector3(h, 0, v); dir = dir.normalized; transform.Translate(speed * Time.deltaTime * dir); }} using System.Collections;using System.Collections.Generic;using UnityEngine;public class rotaion : MonoBehaviour{ void Update() { if(Input.GetKey(KeyCode.W)) transform.Rotate(Vector3.right * 5f); if(Input.GetKey(KeyCode.S)) transform.Rotate(Vector3.left * 5f); } }

캐릭터가 먼저 움직일 방향으로 몸을 틀고 그 후에 회전하면서 이동하는 걸 구현하고 싶습니다.

계층구조와 위의 코드를 활용해서 짜고 싶은데 방법을 모르겠네요.

    아직 답변이 없어요.