###前提・実現したいこと
オブジェクトの向いているほうにオブジェクト自体を飛ばすのを実装したいです。
飛ばすこと自体は出来ているのですが、そのオブジェクトの向きに合わして飛ばす
のにはどのようにすればいいのかわかりません。
###発生している問題・エラーメッセージ
向いている方向にオブジェクトが飛ばない
###該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RrocketPunchi : MonoBehaviour { public bool Moveflg; public GameObject Rrocket; // Use this for initialization void Start() { Moveflg = false; } // Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Q)) { Moveflg = true; } if(Moveflg) { Rrocket.transform.rotation = this.gameObject.transform.rotation; transform.position += new Vector3(0, 0f, 30f * Time.deltaTime); } } //向きに合わして何かするときに使う //transform.position += transform.TransformDirection(Vector3.forward); //void OnTriggerEnter2D(Collider2D coll) //{ // if (coll.gameObject.tag == "Enemy") // { // Destroy(this.gameObject); // } //} }
###試したこと
transform.position += transform.TransformDirection(Vector3.forward);
を使えば向きに合わして何かするのに使えるのは分かったのですが使い方が分からず
###補足情報(言語/FW/ツール等のバージョンなど)
unity C#
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。