- Home /
(2D) How to shoot multiple bullets in different directions
Hello everyone,
i was trying to create a different shooting "system", i basically used to do this by creating a for loop that iterate between all the bullets in a single shot, then based on the counter i add an amount to the current angle so i have a nice looking multiple bullets shot, i tried to do the same algorithm with unity and like always, the result is pretty fancy but not what i really want, i wrote this method to shoot bullets : private Transform myTransform;
public GameObject Bullet; // bullet prefab
void shoot (float reload, int num, float distance)
{
tmpReload += 0.1f;
if (tmpReload >= reload) {
print (tmpReload);
for (int i =0; i<num; i++) {
Quaternion target = Quaternion.Euler (i * distance, 0, 0); // this line is wrong, but i thought this is where i should do it
Bullet.transform.rotation = target;
Instantiate (Bullet, myTransform.position, Bullet.transform.rotation);
}
tmpReload = 0;
}
}
the result i want to achieve is a pretty basic for any 2D shooter game so i think the solution must be quite easy, PS : i tried to do this : Bullet.transform.rotation = Quaternion.Slerp (transform.rotation, target, Time.deltaTime * smooth);
but also i didn't have the result that i was looking for
thank you very much
It would be helpful if you had a visual of the pattern you were looking for.
Answer by Aladine · Aug 10, 2013 at 05:40 PM
Solved : for (int i =0; i
Quaternion target = Quaternion.AngleAxis ((distance * (i - (num / 2))), transform.up);
Instantiate (BulletFab, myTransform.position, target * myTransform.rotation);
}
Your answer
Follow this Question
Related Questions
Rotation and Velocity of bullets. 1 Answer
Ignore a collider when there are multiple ones? 1 Answer
How can I raycast the direction my 2D character is facing? 1 Answer
Why is my GameObject rotation snapping to a certain angle when he reaches its destination? 2 Answers
Relation between two 3D vectors that are in the same plane, to translate to 2D 4 Answers