- Home /
Make multiple Projectiles move at the same Time...
Hello there,
I'm making a 2D, top-down dogfight game and I have a script that makes my fighter shoot.
It only Instantiates the projectile sprite yet. Now, I want the projectile to move, until it hits an object. Here is when I need your help! My fighter can only shoot one Projectile each second, I made a coroutine for that. But how can I make each projectile move.
Here is what I got so far:
void Update () {
if(Input.GetKey(KeyCode.Space) && !shooting) {
StartCoroutine(shoot ());
}
}
IEnumerator shoot() {
shooting = true;
Instantiate(shot, transform.position, Quaternion.identity);
yield return new WaitForSeconds(1);
shooting = false;
}
Hope you can help me! Thanks in advance...
you should add the movement script to the projectile. you can either use transform.Translate(transform.forward * speed); or considering your projectile has a Rigidbody2D attached to it use Rigidbody2D.Velocity = transform.forward.speed; in the start function while you have your drag and angular drag set to 0 in the inspector of the Rigidbody2D.
@taxvi is right. It is just matter of moving your projectile forward (or in any direction) once it is instantiated. Search UA and there are lots of answers discussing various methods of doing it.