Unity でホーミング弾的なものの実装
はじめに
- プレイヤーに向けて移動するホーミング弾的なものの実装
- Vector3.MoveTowards は2点間の特定の位置を返すので、プレイヤーの座標と弾の座標を指定して、Update 毎に距離を詰める
コード
public class Bullet : MonoBehaviour { void Update () { GameObject player = GameObject.Find ("Player"); float speed = 1.0f; float step = Time.deltaTime * speed; transform.position = Vector3.MoveTowards(transform.position, player.transform.position, step); } }