# Ai problems

**URL:** https://forum.kirupa.com/t/ai-problems/260111
**Category:** Uncategorized
**Created:** [May 12, 2008, 6:46pm UTC](https://forum.kirupa.com/t/ai-problems/260111 "2008-05-12T18:46:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mordormaster](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mordormaster](https://forum.kirupa.com/u/mordormaster)
#### Post date: [May 12, 2008, 6:46pm UTC](https://forum.kirupa.com/t/ai-problems/260111/1 "2008-05-12T18:46:57Z")

</div>

hiyar, well its been two months and my game has come along in leaps and bounds until now, i had a basic ai system ready but i seem to have alot of faults with it.

1.)The enemies can go through walls

The enemies can walk straight through walls and basicly i have no idea how to stop them doing that

2.)The enemies dont attack

I tried adding a hittest inside it to play an arm symbol and it will not attack the character

3.)For it to work things must be a certain way

The code means that the character must be in the exact center of the map

i was wondering if anyone could fix any of these problems for me  
thank you in advance

---

<div class="post-metadata">

### Author: ![mordormaster](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mordormaster](https://forum.kirupa.com/u/mordormaster)
#### Post date: [May 18, 2008, 4:47pm UTC](https://forum.kirupa.com/t/ai-problems/260111/2 "2008-05-18T16:47:19Z")

</div>

Could anybody help me please?

---

<div class="post-metadata">

### Author: ![bpalermo](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bpalermo](https://forum.kirupa.com/u/bpalermo)
#### Post date: [May 18, 2008, 11:41pm UTC](https://forum.kirupa.com/t/ai-problems/260111/3 "2008-05-18T23:41:13Z")

</div>

BY the way, I got an unexpected file format error here…

---

<div class="post-metadata">

### Author: ![mordormaster](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mordormaster](https://forum.kirupa.com/u/mordormaster)
#### Post date: [May 19, 2008, 1:06pm UTC](https://forum.kirupa.com/t/ai-problems/260111/4 "2008-05-19T13:06:52Z")

</div>

[LEFT]The file format is flash cs3. i only need one or two of thouse problems fixed, i created alot of other things for the game im making but so far only ai is not working for me, now i have got the enemies walking but they still wont attack, i cant creat a hittest that works for it.[/LEFT]

---

<div class="post-metadata">

### Author: ![bpalermo](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bpalermo](https://forum.kirupa.com/u/bpalermo)
#### Post date: [May 19, 2008, 2:50pm UTC](https://forum.kirupa.com/t/ai-problems/260111/5 "2008-05-19T14:50:13Z")

</div>

I still use Flash 8…

---

<div class="post-metadata">

### Author: ![bluemagica](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bluemagica](https://forum.kirupa.com/u/bluemagica)
#### Post date: [May 19, 2008, 2:53pm UTC](https://forum.kirupa.com/t/ai-problems/260111/6 "2008-05-19T14:53:36Z")

</div>

i also use flash8, and i dont plan on using cs3 anytime soon, instead i will move on to something like flashdevelop which is meant for coding alone…

Anyway, mordormaster, if the code is in as2, then convert the file to fl8 and show, else put your code right here.

---

<div class="post-metadata">

### Author: ![mordormaster](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mordormaster](https://forum.kirupa.com/u/mordormaster)
#### Post date: [May 19, 2008, 8:38pm UTC](https://forum.kirupa.com/t/ai-problems/260111/7 "2008-05-19T20:38:44Z")

</div>

i have converted it to flash 8 format now, but incase that dont work here is the code for the ai itself 🙂

> 

onClipEvent (enterFrame) {  
var herox=(\_root.map.\_width/2)-\_root.map.\_x;  
var heroy=(\_root.map.\_height/2)-\_root.map.\_y;  
// determine the distance using pythag’s theorem  
dist = Math.sqrt( Math.pow( this.\_x - herox, 2) + Math.pow( this.\_y - heroy, 2) );  
// only chase if within 200px, and stop if touching  
if(dist \< 200 && dist \> this.\_width){  
// determine the angle between the hero and the enemy  
angle = Math.atan2( heroy - this.\_y, herox - this.\_x );  
// rotate enemy to face the hero  
this.\_rotation = angle \* (180 / Math.PI);  
// move the enemy along the vector that leads to the hero  
// adjust the value of 5 to change the speed  
this.\_x += Math.cos(angle) \* 5;  
this.\_y += Math.sin(angle) \* 5;  
}else{  
// normal enemy movement when not chasing goes here  
} //if  
}

---

<div class="post-metadata">

### Author: ![mordormaster](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mordormaster](https://forum.kirupa.com/u/mordormaster)
#### Post date: [May 23, 2008, 3:59pm UTC](https://forum.kirupa.com/t/ai-problems/260111/8 "2008-05-23T15:59:41Z")

</div>

right i have fixed the walking through walls and made it attack but i need to be able to make it go for the center of the screen, so far if i make my map any bigger than 700 pixels by 700 pixels it just wont work, can anyone help me?
