Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Getting Enemies to follow a movement pattern

MonjiOMonjiO Posts: 20Member
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?


  • harrioharrio Posts: 234Member
    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.

  • sdparduesdpardue Posts: 110Member
    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.

  • JamesBoucherJamesBoucher Posts: 433Member
    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 Posts: 20Member
    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 Posts: 20Member
    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...
This discussion has been closed.