Page 1 of 1
How to make patrol enemies?
Posted:
Sat May 28, 2011 1:12 am
by pizbi
hi I'm making a game and I'd like to know how to make an enemy that wanders around an area aimlessly.
but the enemy only moves on an x axis
Re: How to make patrol enemies?
Posted:
Sat May 28, 2011 10:24 am
by schnellboot
alright here's a quick demo
I didn't comment so ask if you don't understand something
good luck
Re: How to make patrol enemies?
Posted:
Sat May 28, 2011 11:56 am
by savvy
can use x positioning, when they're created set an actor variable to their x position, then make a variable to define what direction theyre traveling in. form this you can map out their movement and restriction.
create actor ->
- Code: Select all
originalx = x;
draw actor ->
- Code: Select all
if(direct==0)
{x+=2;}
if(direct==1)
{x-=2;}
if(x<originalx-200)
{direct=0;}
if(x>originalx+200)
{direct=1;}
this code will make it move left to right 200 pixels from where it spawned
Re: How to make patrol enemies?
Posted:
Sat May 28, 2011 11:59 am
by schnellboot
savvy it's kinda the same I posted ^^
Re: How to make patrol enemies?
Posted:
Sat May 28, 2011 12:15 pm
by savvy
didn't download it XD
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 5:53 pm
by sunnybubblegum
Thank you for posting this. I also needed an enemy on patrol duty.
However, I was wondering how you would add a pause at each end of his patrol. For example, 'walks right, pauses and looks around, walks left, pauses and looks around, repeat'.
Thanks in advance!
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 6:19 pm
by schnellboot
what do you mean with look around
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 7:49 pm
by sunnybubblegum
I thought it might add something if after the enemy stopped, he then faced up for a few seconds, then down for a few seconds, before continuing his patrol in the other direction. As though he's on the lookout for intruders. Does that make sense?
*I'm making a top-down game, by the way.
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 7:56 pm
by schnellboot
do you want me to implement the look script or just the pause
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 7:58 pm
by sunnybubblegum
Implementing the look script would be helpful to me, if it's not too much trouble.
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 8:51 pm
by schnellboot
sunnybubblegum wrote:Implementing the look script would be helpful to me, if it's not too much trouble.
well, I did the wait here
I added two comments where you can put your look script
I couldn't make the look script because I don't have the sprites and I don't know what you exactly want
I think you can do this on your own
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 9:46 pm
by sunnybubblegum
I just put the script onto my intended enemy and it's working well! I didn't realize timers would be involved, but this is a good introduction for me. I still have to make him look around but hopefully that won't be beyond my level. Much thanks for your help and generosity!
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 10:28 pm
by schnellboot
just an example
Re: How to make patrol enemies?
Posted:
Fri Jul 15, 2011 11:45 pm
by sunnybubblegum
That is almost exactly how he's behaving now. Only I achieved it by adding 6 new cases to the switch function you made. One for facing down (4), ahead (5), up (6), and the same on the other end (7, 8 and 9). They each have their own timers and animations. I don't know if this is a very economic way to do it, but it's working so far.
My next challenge is giving him the ability to spot and then chase you if he's facing you. But I think I'll give my ambition a rest for a minute! :D