Galaga-type enemy AI
Hey unity community, this is my first time posting so do tell me if i break any etiquette.
Now on to my question, im currently practicing coding in C# to teach it to myself. I do this through creating a galaga-type game (top down, 2d, powerups bullets, space etc.).
i have my playercontroller working and all and im starting on the enemy ai. thing is im fully stuck as i cant find anything related to putting 2d enemy objects into a grid, and even less on having them enter a level with a set path. is there any way some of you can help me? or point me in the right direction?
i myself was thinking about using a table, or an array of gameobjects that act as "idle positions" for the enemies to fly to when done "entering" the level. but i would have to check if a gameobject is already taken or not. anyhow, any help is appreciated!.
Answer by arjanwiegel · Feb 16, 2017 at 12:40 PM
If you're new to programming try not to program the movement, but make a simple animation in the animator and trigger that in an animation.
There is really not much AI to Galaga. Everything is a scripted animation that does not respond to your actions except for the direction of the bullets maybe.
Adding simple animations to individual enemies could make them do "real" attacks.
Why don't you first place the enemies by hand for a start, like space-invaders and parent the "wave" to a common gameobject that moves from side to side and down slowly. (animation). The then only needs to change the sprites, so it looks like it is animating, die when a bullet hits it and sometimes drop a bullet down. You could make multiple waves or simply increase the speed of a single repeating wave.
thanks for this tip, i will try this first. the space invaders type roster by childing the enemies and animating the parent object is a smart train of thought.
i did try animating individual enemies but every time i instantiate that prefab the animation gets called at the 0x 0y 0z axis relative to the worldspace. if i can find out how i can put that relative to the parent's axis then im all set.
still thanks bunches!
To animate a gameobject relative to another transform make a prefab which is the enamy and give it a child that has the animation. That way you can place the enemy anywhere you want and animate its child from there.
thats so smart, cant believe i hadn't thought of that! thanks!
Your answer
Follow this Question
Related Questions
Object movement algorithm 0 Answers
Destroy a game object after holding Mouse 0 for some time 1 Answer
How to rotate a 2d object with joystick in unity ? 0 Answers
How do I create a 2D Seamless World Map? 1 Answer
My enemy is going the wrong way 1 Answer