一点を中心に回転(TPS視点)
用意するもの
- Player(中心点にしたいObject)
- CenterRotation(回転を補助するObject)
- MainCamera(カメラ)
やること
- PlayerとCenterRotationのポジションを同期(この時子要素に入れない)
- RotationObjの子要素にCameraをセット.
実践
(1)PlayerとCenterRotationのポジションを同期するするスクリプトを書いてあげる
public GameObject player; private Vector3 offset; // Use this for initialization void Start () { offset = transform.position - player.transform.position; } // Update is called once per frame void Update () { transform.position = player.transform.position + offset; }
(2)CenterRotationを回転させるスクリプト
void Update () { if (Input.GetKey(KeyCode.Q)) { this.transform.Rotate(new Vector3(0, 1, 0), 90 * Time.deltaTime); } if (Input.GetKey(KeyCode.E)) { this.transform.Rotate(new Vector3(0, 1, 0), -90 * Time.deltaTime); } }
(3)RotationObjに(1)と(2)のスクリプトをアタッチ! コレで終わり!
ツリー