A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: actions activated by measure

  1. #1
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215

    actions activated by measure

    hey guys,

    i was wondering, is it possible for an action to be
    pulled off by distance from a certain object?

    say my hero is like 60 away from the enemy (60 in terms of _x)

    and if my hero is within 60x from the enemy, then
    the enemy will attack

    if my hero is farther than 60, then do something else...

    is that possible?

    if so, can anyone show me how this is done?

    thnx a lot, erhm, a bunch!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  2. #2
    Senior Member St. Nick's Avatar
    Join Date
    Sep 2003
    Location
    Ontario, Canada
    Posts
    312
    code:


    //On the enemy

    if(Math.abs(this._x)<heroDist){
    attack();
    } else{
    walk();
    }




    The Math.abs part ensures that the hero can approach from left or right. Does this help?
    - St. Nick

  3. #3
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    htnx dude! I think i get your idea

    Math.abs, its like saying that the number is
    both negative and/or posistive right?

    oh and, how do i specify the distance from the hero?

    anyhoo, thnx a bunch!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  4. #4
    Senior Member St. Nick's Avatar
    Join Date
    Sep 2003
    Location
    Ontario, Canada
    Posts
    312
    Yeah, Math.abs is the absolute value, which means positive or negative. Sorry, I messed it up and forgot a section! I can't believe it... sorry.

    Anyways, should read:

    if(Math.abs(this._x-hero._x)<heroDist){

    heroDist would be the distance away from the hero where the enemy would start to do something. In your example, this would be 60. Sorry for the screw up
    - St. Nick

  5. #5
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    I used two movie clips, one named mc1 and the other mc2, then i used this code in the frame.

    Code:
    _root.mc1.onEnterFrame = function() {
    	xDist = Math.abs(Math.round(_root.mc1._x-_root.mc2._x));
    	if (xDist<60) {
    		trace("ATTACK!!!");
    	}
    };
    It checks how far mc1 is from mc2, rounds it up to a postive and round number, then you can check to see how far away it is.

    Hope it helps

  6. #6
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    oh hey St. Nick, dont worry bout it!

    thnx for the help you guys, now i have a
    good start off with my AI!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

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