# \[as2\] Random Direction AI within area\_mc

**URL:** <https://forum.kirupa.com/t/as2-random-direction-ai-within-area-mc/280123>\
**Category:** programming\
**Created:** [January 23, 2009, 12:31am UTC](https://forum.kirupa.com/t/as2-random-direction-ai-within-area-mc/280123 "2009-01-23T00:31:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olaf\_Forkbeard](https://avatars.discourse-cdn.com/v4/letter/o/c89c15/32.png) [@Olaf\_Forkbeard](https://forum.kirupa.com/u/Olaf_Forkbeard)\
**Post date:** [January 23, 2009, 12:31am UTC](https://forum.kirupa.com/t/as2-random-direction-ai-within-area-mc/280123/1 "2009-01-23T00:31:03Z")

</div>

I am trying to build an AI that only moves when the movement is off of the drawn part of another Movie Clip. Lets call the AI’s body “gob\_mc” (goblin) and the walls for where it cannot walk “gobWall\_mc”. At the moment I’m not workin on the goblins appearence so I’m using a 50x50 yellow square with no rotation etc.

Anyway I came up with this “ish.”

Create a random number for each x and y.  
If those x and y coordinates are not hitting wall\_mc then go ahead and dynamic tween that way.  
If those x and y coords are hitting a wall then recalculate them and repeat check for dynamic tween.

And there lies my problem. This recalculation is lagging my system (30 fps). Does anyone know a simpler way to do this… or do I need to clarify anything. I’m sure I’m missing something thats fairly simple as most things go.

Thanks for any help.
