A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: HELP - dude, wheres my hitTest?

  1. #1
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110

    HELP - dude, wheres my hitTest?

    Hi all,

    I hadthis problem a while back, so Im putting the question to you experts. I need my small npc dudes to walk the opposite way whenever they hit a wall (North, South, East or West). I've ued hitTest on the guy, and he moves up the screen towards the test wall where he hits it and doesn't move in the opposite direction (despite my best scripting attempts - Below).

    onClipEvent (load) {

    dudeSpeed=5;
    this.gotoAndStop(1);
    }

    onClipEvent (enterFrame) {

    this._y-=dudeSpeed;

    if (this.hitTest( _root.wall ) ){
    this._y=
    this._y+=dudeSpeed;

    }


    }

    It compiles correctly, runs correctly, but when it reaches the "Wall" MC, it just stops in its tracks. Doesn't move down the y+ axis as requested.
    Any suggestions? Much appreciated

    Kris

  2. #2
    Optimist Prime StenFLASH's Avatar
    Join Date
    Mar 2004
    Location
    Canberra, Australia
    Posts
    252
    The reason it stops in its tracks is because you've told it to go left at a speed of 5. Once it hits the wall you've then told it to go right at a speed of 5. The only thing is it's still trying to go left at a speed 5 making its current speed actually 0, so that's why it stops dead in its tracks.

    You should try coming up with a function to allow the NPC to move in a random direction (for a random amount of time) and once it hits something, make it's direction change via a direction variable rather than trying to affect its speed.

  3. #3
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    You might also wanna check out:

    code:

    this._y=




    Not sure why its in there, but it definatly cant be helping matters.

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  4. #4
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    Actually, tis up and down, and I know about the function :P question is: how?? Oh, and the this._y= was a typo, didnt really affect it.

  5. #5
    Member
    Join Date
    Jan 2004
    Location
    Ontario,Canada
    Posts
    76
    shouldnt you just be able to change DudeSpeed?

    if(this.hittest(_root.wall){
    DudeSpeed=(-5)
    }

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