- Home /
How do I create bullet patterns (multiple bullets, different world positions)
Hi,
I'm trying to create enemies that create bullet hell shooter patterns. These require multiple bullets to be fired in circular or arc patterns at once. My simple question is what is the best way to go about this?
should I:
1) Script an enemy with multiple bullet "gameobject" and then instantiate them in code, once the player is close?
2) Should I put all bullet objects into one prefab and then instantiate that prefab in code. (I tried this, and for some reason, prefabs don't like object with duplicate names.)
Not sure if either of these is the best way. But neither has worked properly. Option 1 creates two bullets in the same position; which makes it look like just one bullet has instantiated.
I appreciate any input you have. Please let me know if clarity is required.
Answer by Billamu · Sep 25, 2010 at 09:52 PM
This piece of code will do it. It's not fancy but it does the job.
var bullet : Transform; var bulletAmount : float = 8; private var bulletcoords : Vector2; private var rot : Quaternion;
function Start() { for (var i : float = 0; i<bulletAmount; i++) { rot.eulerAngles = Vector3(0,270+((i/bulletAmount)*180),0); Instantiate(bullet, Vector3.zero, rot); } }
What I discovered while coding this is that my variables needed to be float
s, not int
s; otherwise the division of i/bulletAmount
doesnt work.
http://unity3d.com/support/documentation/ScriptReference/Quaternion-eulerAngles.html
Thanks for your help Bill. Is there any place I can find more info on While loops and for loops in Unity?
Answer by vestax_ion · Jul 13, 2011 at 07:30 PM
I am learning code, i wanted to figure how to make the bullets change position as well as rotation, the answer was to change the instantiate line to:
Instantiate(bullet, Vector3(0, i ,0), rot);
This is not an answer and should not be posted in the answers section.
If you have a question, open a new thread and link to this one for clarification.
so i get -4 on this forum for asking about a line of code posted in a thread, within the same thread?
You're right, that was harsh (I get cranky before lunch...).
Fixed it, but ya, reserve the answers section for answers.
Answer by spinaljack · Sep 25, 2010 at 09:36 PM
You could have a "shooter" game object that is just an empty game object that sits where the bullets appear from.
Instantiate a bullet each frame and rotate the object by some amount using rotate
Keep firing and rotating for as many frames as you want to fire for.
You can also use for loops to fire and rotate multiple times in a single frame.
Your answer
Follow this Question
Related Questions
All Three Game Objects Fire At Once 1 Answer
Bullet Pattern for Bullet Hell 1 Answer
Shmup style enemy behavior 0 Answers
how to make bullet ascend/descend relative to uneven ground level? 2 Answers
2D Bullet Hell Game - Bullet Patterns 2 Answers