This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-04-06 21:57:36

DisposableHero
Scratcher
Registered: 2010-04-01
Posts: 5

I need help with enemy AI movement

Ok man. I need help. Im trying to make a game where the enemy follows the player. but only on the x-axis. like when my player jumps, the enemy starts to float toward them. i want to make it where it only follows you on an x-axis. so if im in the air, the enemy will be below me, trying to get to me but not able to go up. Get what im sayin? Can you tell me how?

Offline

 

#2 2010-04-06 22:03:04

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: I need help with enemy AI movement

Is this what you mean?

http://img32.imageshack.us/img32/5448/xpos.gif


http://i48.tinypic.com/2z5pqad.png

Offline

 

#3 2010-04-06 22:03:43

GirWaffles64
Scratcher
Registered: 2009-08-09
Posts: 1000+

Re: I need help with enemy AI movement

Ok, on the enemy, set a script saying

When Green Flag Clicked
Forever:
Set X To (Xposition0 of (player)

Last edited by GirWaffles64 (2010-04-06 22:05:43)


hey kiddoes i'm back

Offline

 

#4 2010-04-06 22:05:50

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need help with enemy AI movement

Try this

forever{
if (targetX>xposition){
change x by 10}
else{
change x by -10
}
}


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2010-04-06 22:16:12

DisposableHero
Scratcher
Registered: 2010-04-01
Posts: 5

Re: I need help with enemy AI movement

what does it mean by "target"?

Offline

 

#6 2010-04-06 22:22:16

DisposableHero
Scratcher
Registered: 2010-04-01
Posts: 5

Re: I need help with enemy AI movement

ok. exactly what i mean is: for example, these pieces

<move(  )steps>
<point towards(

EXCEPT i dont want it moving on the Y-axis WHATSOEVER i still want it to follow me at a controlled speed, just not having the ability to move up or down

Offline

 

#7 2010-04-06 22:33:57

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need help with enemy AI movement

DisposableHero wrote:

what does it mean by "target"?

Replace target with whatever you want to follow. The script will follow its target on the x axis at a controlled pace.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#8 2010-04-06 22:41:45

DisposableHero
Scratcher
Registered: 2010-04-01
Posts: 5

Re: I need help with enemy AI movement

Wait. Can you rewrite your example script please? I dont quite understand what i need to do...

Offline

 

#9 2010-04-06 23:13:11

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need help with enemy AI movement

Its really really basic
http://www.newgrounds.com/dump/draw/c9257eb325d812fe9e397ccccfcecf51.jpg


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#10 2010-04-09 18:21:24

DisposableHero
Scratcher
Registered: 2010-04-01
Posts: 5

Re: I need help with enemy AI movement

okay. i did that and it works. thank you. but one more problem. the enemies are starting at places i did not intend them to start at. i even forced them to go to a certain spot but they keep overriding it 0.o

Offline

 

#11 2010-04-09 21:18:02

samurai768
Scratcher
Registered: 2009-07-21
Posts: 1000+

Re: I need help with enemy AI movement

DisposableHero wrote:

okay. i did that and it works. thank you. but one more problem. the enemies are starting at places i did not intend them to start at. i even forced them to go to a certain spot but they keep overriding it 0.o

Did you get X and Y mixed up? That happens to me sometimes  tongue

Offline

 

Board footer