Getting Enemies to follow a movement pattern

MonjiOMonjiO Member Posts: 20
edited November -1 in Working with GS (Mac)
So, first off, I want to say that my art team and I thank everyone here for their help on my last problem. Now, for the one that's keeping me (but not them, naturally) awake: can I make an enemy follow a set movement pattern?

What I'm trying to do is get the enemies to move to the top of the screen, then the bottom, following this pattern until destroyed. I also have a spawner that is randomly creating the enemies at different Y co-ordinate levels (I'm trying to simulate "squadron" style movement).

What I'm doing at this point is that I have two invisible actors at the top and bottom of the camera, stretching throughout the stage. They're named, creatively enough, Top and Bottom. In my enemy behaviors, I've got a rule where, if they collide with Top then they will move down, and vice-versa for collision with Bottom.

The first hurdle I had to overcome was getting them to move from their spawn point, which I initially did by creating a Move behavior. This got them to move fro their spawn, but now when they hit Top or Bottom they do not move in the pattern I need them to, instead following along the edge of Top/Bottom.

So, basically, what I need is a way for movement direction, but not velocity, to change after collision with an actor. Is this possible?

Comments

  • harrioharrio Member Posts: 234
    what's cookin,

    what type of movement behavior are you using? some are easier to deal with than others when it comes to changing direction. also, can you post the movement code? there might be an error in it causing it to not function as you want.

    noodles...
  • sdparduesdpardue Member Posts: 110
    I solved a similar problem by using the Change Velocity behavior.

    In the code for the enemy, I use an initial Change Velocity to set the direction and velocity after it's spawned.

    Next, I have two rules for when they hit the Top and Bottom:

    Rule 1: When Actor receives event Overlaps or Collides with Actor of type Top
    Change Velocity -- Direction 270 (down) relative to scene
    Speed = whatever you want

    Rule 2: When Actor receives event Overlaps or Collides with Actor of type Bottom
    Change Velocity -- Direction 90 (up) relative to scene
    Speed = whatever you want

    I also have an additional rule that destroys the actor when it collides with... well, whatever is supposed to destroy it.

    Change Velocity (instead of Move) is what solved it for me.

    Hope this helps.

    Steve
  • JamesBoucherJamesBoucher Member Posts: 433
    If you're looking to get the enemies to move toward an actor I used Accelerate Toward, and Rotate to Position. I pass the X and Y position to both and set them relative to scene. You may have to offset angle in Rotate to Position depending on your image. I hide to offset angle by 90.

    This makes the enemies always go after the actor and turn the enemies to always be facing the actor when they're chasing.
  • MonjiOMonjiO Member Posts: 20
    Okay, first off I do want to thank everyone for the advice so far, it's been immensely helpful and it's gotten me to try a couple of things I wouldn't have otherwise seen. However, I'm still running into the same issue. So, perhaps a more thorough description will help.

    Following an initial Move the enemies engage in when they spawn, they move up and to the left (towards the player). They keep moving in this direction until they hit the Top actor, in which case they bounce off (following the Top's collision). At this point, they should begin heading towards the Bottom actor but instead they move again towards Top, creating this weird bouncing train of enemies.

    I've tried changing everything to a Change Velocity instead of a Move, but I'm encountering the same problem as before. I'm going to try JamesBoucher's suggestion and use the move towards behavior at this point, but I'm beginning to think it's more of a logic issue than a behavior issue at this point...
  • MonjiOMonjiO Member Posts: 20
    Okay, update: thanks to James and spardue, I was able to figure out my problem. It was mostly a logic issue (where I was placing CV behaviors relative to rules on movement), but it's working right now!

    Now all that's left is the interminable fiddling to get the movement just right...
Sign In or Register to comment.