Search Unity

Can anyone help with enemy pathing within a 2D shooter?

Discussion in 'Scripting' started by xsharkox, Oct 31, 2014.

  1. xsharkox

    xsharkox

    Joined:
    Aug 24, 2014
    Posts:
    10
    Currently trying to do some form of pattern for enemies to move in for the 2D shooter im making, the scene scrolls down so the ship is facing up. I want to be able to create a script that will be reusable for e.g. script 1 would have a certain pattern to its movement so if i just dropped it onto a enemy ship or even perhaps call a method that would do a certain pattern. the code needs to be as reusable as possible so if sometime in the future i wanted to make a level editor for e.g. i could maybe drop the patterns onto the scene through the editor or just have the scripts create the pathing using on screen coordinates if thats possible? i'm a total amateur at game Dev and unity so any help would be massively appreciated :)
    Any tutorials for help with this sort of enemy pathing system would also be massively appreciated!

    Edit: The kind of pathing i'm looking for is something like the pathing in "Galaga arrangement"
    I really love the pathing in that game, the way the enemies come from any of the sides and form a kind of position as a group then dispersing out.
     
    Last edited: Oct 31, 2014
  2. xsharkox

    xsharkox

    Joined:
    Aug 24, 2014
    Posts:
    10
    bump, anyone please?
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    I generally, if you want to get into complex pathing, would use a Tween API. I use HOTween. It allows you to create a path that a transform can traverse.
     
  4. xsharkox

    xsharkox

    Joined:
    Aug 24, 2014
    Posts:
    10
    Would the flocking algorithm work? and using that with waypoints as well? i've just heard about it so don't have any clue as to how to implement it. currently looking it up and maybe if i could, find something that would help make it easier to implement into Unity. If anyone has an ideas or info on how to do this or has a better solution, I'm open :) Thanks in advance
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    It's very easy once you get used to it. If you are a beginner tho, iTween is easier. That being said, once you get HOTween, it is easy to use, and very easy in the engine.

    Both can use paths. Generally, in HOTween, I create a number of transforms, to use as the path. Place them accordingly. Gather each postion, pass it into an array, this array is used as a path for HOTween.

    ITween, has a full component that is much more editor friendly. I use HOTween tho since it is much faster. Plus other features. For your case, I would reccomend iTween.

    You can create your path. Then run he path as you like.



    However if your game is like space invaders, I may use any pathing sparingly, and instead use translate(). It's really up to your specific needs.
     
  6. GamerYou

    GamerYou

    Joined:
    Jun 13, 2013
    Posts:
    19