- Home /
2D Bullet Hell Game - Bullet Patterns
Hello Im creating a 2d bullet hell game from the top down view in unity and Im having a bit of a problem I dont know how to make certain patterns. Heres a video of something similar that Im trying to recreate http://youtu.be/jeU9ff6KAXQ
@2:20 thats the type of bullet movement that I want to recreate I know how to do all the other types except that one so if anyone could help me write a script for that type of movement It would be vary much appreciated! Im using JavaScript also
Ive also come across this page I think this is what Im looking for but I dont know how to apply it Firing a curtain of bullets Thanks in advance!
Answer by CHPedersen · Dec 29, 2011 at 11:35 AM
People probably won't write a whole script for you, but your question can be relatively easily answered insofar as the necessary math is concerned. :)
Take a look at the video clip you posted again and this time, pay attention to just one single bullet. Do you see how it's not actually changing direction? Every bullet just follows a straight line after getting fired. It's the 7 emitters (cannons or whatever) that rotate a little bit back and forth around a common point in the center of the enemy, and since they're constantly emitting bullets while rotating, the bullets appear to follow that "flower"-pattern you see.
Position the emitters in a circular pattern around the enemy's center and find a way to mimic the rotation, and your bullets will behave the same.
Wow thank you I see how it works now I feel so stupid that I did not see it before, So all I would have to do is rotate the emitter around its y axis a certain number of degrees every couple of seconds so depending on the degree and the time of the rotation influences the shape of the pattern? Is that correct?
That is exactly correct. It's like the kind of fireworks where multiple spark-fountains are attached to a wheel, and you nail the wheel to a wall or a tree, and it rotates when you light them, you know? Sort of like the one in this image:
http://farm4.static.flickr.com/3154/2678082574_8a9a75d1a8.jpg
The sparks behave exactly like you want your bullets to do - They're shot straight out, but look like a spiral because the fountains rotate, and so move a little bit every time a new spark gets emitted.
Answer by ImpusNatus · Dec 29, 2011 at 12:29 PM
Something like this might work?
It's only setup to modify, oscillate, on x. Easy to apply to the other channels.
using UnityEngine;
using System.Collections;
public class ObjectOscillator : MonoBehaviour {
public float speedMult = 1.0f;
public float rangeMult = 1.0f;
// Use this for initialization
public GameObject bullet;
public float shootInterval = 1.0f;
float basex = 0.0f;
float shootTimeAc = 0.0f;
// Update is called once per frame
void Start() {
basex = transform.position.x;
}
void Update () {
Vector3 position = transform.position;
float interval = Mathf.Sin(Time.time * (speedMult / rangeMult)) * rangeMult;
bool shoot = false;
if(Time.deltaTime + shootTimeAc > shootInterval)
{
shootTimeAc = 0.0f;
shoot = true;
}
else
shootTimeAc += Time.deltaTime;
position.x = basex + interval;
transform.position = position;
if(shoot)
Instantiate(bullet, transform.position, bullet.transform.rotation);
}
}
Your answer
Follow this Question
Related Questions
Make a Gun fire multiple times 3 Answers
Object pool shooting not working 0 Answers
Player bullet is fired but spawns ahead of the player character in Unity. 1 Answer
shot delay in between bullets 1 Answer
Spreading Fire (Bullets) 3 Answers