So I’m trying to make a enemy that will fire 3 bullets going in 3 different directions based on where the player is, sort of like how a 2d space shooter would do it. Example drawing
:
Would I change the quaternion.identity or would I change what moveDirection means?
How would I go about doing this, any help is thanked! Here is what I’ve got so far.
Code On Prefab:
{
public float moveSpeed;
public float lifeTimeWeb;
public int damage;
Rigidbody2D rb;
Player target;
Vector2 moveDirection;
void Start()
{
rb = GetComponent<Rigidbody2D>();
target = GameObject.FindObjectOfType<Player>();
moveDirection = (target.transform.position - transform.position).normalized * moveSpeed;
rb.velocity = new Vector2(moveDirection.x, moveDirection.y);
Destroy(gameObject, lifeTimeWeb);
}
void OnTriggerEnter2D (Collider2D collision)
{
//Other Code
}
}
Enemy Bullet Code:
public Transform shootPoint;
public GameObject bullet;
public void CheckIfTimeToFire()
{
if (Time.time > nextFire){
anim.SetTrigger("attack");
Instantiate(bullet, shootPoint.position, Quaternion.identity);
nextFire = Time.time + fireRate;
}
}