ショット
ランチャーとボール
ショットの機構をつくるには様々な方法がある
・ランチャーオブジェクトにはプレハブ化された弾を撃ち出すスクリプト
・弾丸である弾に撃ち出される際に加える力、ベロシティーを設定する方法がある
<弾側>
using UnityEngine;
using System.Collections;
public class tutoBall : MonoBehaviour {
// Use this for initialization void Start () { this.rigidbody.velocity = new Vector3 (-10,9,0); //最初に一度だけ力をくわえている } // Update is called once per frame void Update () { } //カメラの視界外に行くと実行される void OnBecameInvisible(){ Destroy(this.gameObject); }
}
<ランチャー側>
using UnityEngine;
using System.Collections;
public class Launcher : MonoBehaviour {
public GameObject ballPrefab; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetMouseButtonDown(1)){ Instantiate(this.ballPrefab); } }
}
メモ
機敏な物理反応にはphysicを-9.81から-20に変える手段もある
ユニティ上の1ユニットは1mであり現実世界の物体として当てはめると
ふわふわと軽い動きに感じる時もある。そのためゲーム的に気持ち良い動きにするために
やや大げさな「-20」にするは有用であると考えられる
メニュー
- 最終更新:2014-06-13 12:08:58