現状
奥から車がたくさん出てくる
敵のスピードがランダムなので渋滞みたいになる
実現したいこと
敵同士がぶつかったらはじかれたように片方のスピードを少し上げたい
例えば後ろから車に突撃されたら突撃された方のスピード増やす
試したこと
Physic Materialを使ってみたがうまくいかなかった
該当コード
unity
1敵移動コード 2public class EnemyMove : MonoBehaviour 3{ 4 public float speed;//移動スピード 5 private int number; 6 public GameObject smoke; 7 8 // Start is called before the first frame update 9 void Start() 10 { 11 number = Random.Range(3, 12); 12 speed = number; 13 } 14 15 // Update is called once per frame 16 void Update() 17 { 18 //フレームごとにzポジションを移動させる 19 transform.Translate(0, 0, -1.0f * speed * Time.deltaTime); 20 21 if (transform.position.z < -5.0f)//z座標が-5以下だった場合 22 { 23 24 Destroy(gameObject);//破壊 25 } 26 } 27 void OnCollisionEnter(Collision collision) 28 { 29 Collider thiscol = GetComponent<Collider>(); 30 Vector3 hit = thiscol.ClosestPointOnBounds(collision.transform.position); 31 if (collision.gameObject.CompareTag("Player")) 32 { 33 GameObject go = Instantiate(smoke, hit, Quaternion.identity) as GameObject; 34 go.transform.parent = transform; 35 } 36 37 } 38} 39
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。