Getting Enemies to follow a movement pattern
MonjiO
Member Posts: 20
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?
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
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...
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
This makes the enemies always go after the actor and turn the enemies to always be facing the actor when they're chasing.
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...
Now all that's left is the interminable fiddling to get the movement just right...