# Very VERY simple AI problems AND another thing

**URL:** <https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375>\
**Category:** Uncategorized\
**Created:** [April 4, 2006, 6:49pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375 "2006-04-04T18:49:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)\
**Post date:** [April 4, 2006, 6:49pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/1 "2006-04-04T18:49:14Z")

</div>

So basically I had AI problems yesterday and I have it today. The Goblin is supposed to attack when the Hero gets to close.

Enemy.onEnterFrame = function()  
{  
if (Enemy.\_x - Hero.\_x \>= 30)  
{  
trace(“ATTACK THE INNOCENT HOMES AND VILLAGES!”);  
\_root.Enemy.gotoAndPlay(Attack);  
}  
else  
{  
trace(“Peace”);  
}  
}

I think it’s jsut a problem with the goblin animation sequence, but I’m not entirely sure.

My other problem is in a different project of mine. It just doens’t shoot more than one bullet, I shoot once, and if I shoot again my first dissapears and my second one appears at my gun.

i = i+1;  
var depth = 1;  
onMouseDown = function () {  
var b = attachMovie(“bullet”, “bullet”+depth, depth);  
depth++;  
b.\_x=MainHero.\_x, b.\_y=MainHero.\_y;  
b.\_t = Math.atan2(this.\_ymouse-b.\_y, this.\_xmouse-b.\_x);  
b.onEnterFrame = function() {  
this.\_x += Math.cos(this.\_t)\*9;  
this.\_y += Math.sin(this.\_t)\*9;

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [April 4, 2006, 8:24pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/2 "2006-04-04T20:24:22Z")

</div>

```auto

Enemy.onEnterFrame = function()
{
if (Math.abs(this._x - Hero._x)>= 30)
{
trace("ATTACK THE INNOCENT HOMES AND VILLAGES!");
_root.Enemy.gotoAndPlay(Attack);
}
else
{
trace("Peace");
}
}

```

the way you had it would make it so the enemy would have to have a greater \_x, while the code i posted can be eather or

---

<div class="post-metadata">

**Author:** ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)\
**Post date:** [April 4, 2006, 9:42pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/3 "2006-04-04T21:42:51Z")

</div>

Oh I see. Thx Bomb. But do you know what’s wrong with the bullets?

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [April 4, 2006, 9:48pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/4 "2006-04-04T21:48:18Z")

</div>

is this your whole code?

```auto

onMouseDown = function () {
   var b = attachMovie("bullet", "bullet"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
   b._x=MainHero._x, b._y=MainHero._y;
   b._t = Math.atan2(this._ymouse-b._y, this._xmouse-b._x);
   b.onEnterFrame = function() {
      this._x += Math.cos(this._t)*9;
      this._y += Math.sin(this._t)*9;
   }
}

```

now you don’t have to worry about depths

---

<div class="post-metadata">

**Author:** ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)\
**Post date:** [April 4, 2006, 10:09pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/5 "2006-04-04T22:09:20Z")

</div>

No it’s not my whole code, it’s just my duplicating code which seemed to be the source of the problem…

MAN BomBsledder! Your a life saver, thx for the help with the bullets!

:hugegrin: :hugegrin: :hugegrin: :hugegrin:

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [April 4, 2006, 10:16pm UTC](https://forum.kirupa.com/t/very-very-simple-ai-problems-and-another-thing/184375/6 "2006-04-04T22:16:52Z")

</div>

glad to be of help
