# Rpg AI fight

**URL:** https://forum.kirupa.com/t/rpg-ai-fight/242534
**Category:** programming
**Created:** [October 27, 2007, 1:05am UTC](https://forum.kirupa.com/t/rpg-ai-fight/242534 "2007-10-27T01:05:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Mr\_beef](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Mr\_beef](https://forum.kirupa.com/u/Mr_beef)
#### Post date: [October 27, 2007, 1:05am UTC](https://forum.kirupa.com/t/rpg-ai-fight/242534/1 "2007-10-27T01:05:52Z")

</div>

Well my concept is when you enter the scene (the frame) the enemy will slowly walk to you. You can only move along the x axis. When you press space you attack and cant move, if your touching the enemy…

Well what i’m currently doing isn’t working. I’m new to flash but i find i learn well when i fiddle with code to make it work or have help and direction. I tried the first option and it didn’t work. So here i am, after reading these forums for a few days. Problem:

enemy goes to “attack1” but freezes on first frame  
character wont hitTest the enemy1 so cant attack

character:

> onClipEvent (enterFrame){  
> {  
> if (Key.isDown((Key.SPACE)) and (\_root.enemy1.hitTest(\_x, getBounds(\_root).yMax, true))){  
> this.gotoAndPlay (“attack”);  
> mySpeed = 0;  
> }  
> else mySpeed = 5;  
> }  
> }

enemy1:

> onClipEvent (enterFrame)  
> {  
> moveSpeed = 3  
> distX = Math.ceil(\_root.character.\_x-\_root.enemy1.\_x);  
> if (distX\>-100 && distX\<10) {  
> {  
> this.gotoAndPlay (“attack1”);  
> }  
> }  
> else{  
> \_x -= moveSpeed  
> this.gotoAndPlay(2)//walk action  
> }

if(\_root.character.hitTest){  
moveSpeed = 0  
}  
}

Please keep in mind i am new to flash. So if you do find any faults please explain why it wont work.

Thanks.
