Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized
1 Camera.main.transform.forwardを公式リファレンスは英語で書かれておりgoogle翻訳にかけましたが意味がわからずtransform.forwardについて知ら
べるとワールドの青軸とあるのですがカメラなのでカメラの青軸つまりZ軸でよろしいのでしょか?いまいちわかりやすい翻訳を得られないので質問しました
2 .normalizedとはリファレンスを見るとmagnitude を 1 としたベクトルを作成しますとありますがmagnitudeを調べるとベクトルの読み取り専用などとありますがベクトルを作るという意味でしょうか?
c#
1public class UnichanController : MonoBehaviour { 2 private Animator anim; 3 private Rigidbody rb; 4 private float moveSpeed = 3.0f; 5 float inputHorizontal; 6 float inputVertical; 7 8 // Use this for initialization 9 void Start () 10 { 11 anim = GetComponent<Animator>(); 12 rb = GetComponent<Rigidbody>(); 13 } 14 15 void FixedUpdate() 16 { 17 // カメラの方向から、X-Z平面の単位ベクトルを取得 18 Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; 19 20 // 方向キーの入力値とカメラの向きから、移動方向を決定 21 Vector3 moveForward = (cameraForward * inputVertical) + (Camera.main.transform.right * inputHorizontal); 22 23 // 移動方向にスピードを掛ける。ジャンプや落下がある場合は、別途Y軸方向の速度ベクトルを足す。 24 rb.velocity = moveForward * moveSpeed + new Vector3(0, rb.velocity.y, 0); 25 26 // キャラクターの向きを進行方向に 27 if (moveForward != Vector3.zero) 28 { 29 transform.rotation = Quaternion.LookRotation(moveForward); 30 } 31 } 32 33 34 // Update is called once per frame 35 void Update () 36 { 37 inputHorizontal = Input.GetAxisRaw("Horizontal"); 38 inputVertical = Input.GetAxisRaw("Vertical"); 39 } 40} 41
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。