unityでカメラをyを軸に回転させ、向いた方向を前として、wで前進、sで後進、aで左、dで右に動かすスクリプトを書きたいのですが、軸で回ることはできても、どうしてもワールドのx,z方向にしか進めません。
どのようなスクリプトを書けばいいでしょう。
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class cameraController : MonoBehaviour { 6 public float speed; 7 public GameObject a; 8 9 Vector3 movement; 10 Rigidbody rb; 11 12 void Start(){ 13 rb = GetComponent<Rigidbody> (); 14 } 15 16 void FixedUpdate(){ 17 float h = Input.GetAxisRaw ("Horizontal"); 18 float v = Input.GetAxisRaw("Vertical"); 19 20 transform.rotation = Quaternion.Euler (0, a.transform.localEulerAngles.y, 0); 21 movement.Set (h, 0f, v); 22 movement = movement.normalized * speed * Time.deltaTime; 23 rb.MovePosition (transform.position + movement); 24 } 25}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。