A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Major AI problem

  1. #1

    Angry

    I want to design a movieclip class called 'walkingBoundaries' or something, so i can put my little men on a map, and they will only walk where they are allowed to walk.

    I have a man movie clip that can make the men move around in random directions, changing every so often, but there are no restriction as to where they can go.

    I not talking just confining then to a rectangle. I want the class to be multiple rectangles of different sizes, so they can walk around a street layout.

    check out a demo of what i have so far -

    http://www.guyincognito.co.uk/test engine.html

  2. #2
    Member
    Join Date
    Jan 2001
    Posts
    72
    I am a little unclear as too what you want but i think i know what you are talking about. What i would do is have one movie clip which you have all the rectangles that the AI can't go, then do a simple hittest within the AI.

    You need to test to see if the AI will hit the MC and if not then it will move. Lets make is simple for the example and say that the AI guy is just moving +5 in both the x and y directions,and the rectangles mc is called rectangles, something like this would work:

    If (!_root.rectangles.hitTest(_x+5, _y+5, true)
    _x += 5
    _y += 5
    )

    Understand? If not reply and i will explain more.

  3. #3
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    Oh wow, I never realized what those other params were for (the +y and +x). I had been making 4 clips, one for each side of the clip and moved them with it, hit testing each one.. a lot of work..


    Thanks, you made my day!

  4. #4
    thanks for the contribution dj blaze, but i was hoping to avoid the hitTest method, as it seems pretty bulky and proccess hungury.

    I also find hitTest unreliable in getting the behavior right when its hard to predict how the threads are being processed in flash.

    e.g calling the hitTest when the man movie clip graphic is one size, it might test false.
    but then when the graphic moves to the next frame, the shape has changed, and the hitTest is already interlinking.

    You end up getting very unreliable jumping of position.

    I was hoping someone might have some nice bitwise arithmatic on checking positions, and avoiding using the hitTest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center