A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: hitTest problem

  1. #1

    hitTest problem

    Actionscript v2. MX2004

    How do i stop my man bumping into a wall? This is my script so far,

    if (Key.isDown(Key.RIGHT)) {
    play();
    _x += movespeed;

    man.hitTest(_x+1, _y, true){need script for not letting man move to right}

    Please correct my script if it is wrong and if possible, provide me with the code for not letting man move to right. (The wall's instance name is "walls")

  2. #2
    A Guy With a Hat HumbuckeR's Avatar
    Join Date
    Apr 2004
    Location
    Portugal
    Posts
    228
    Hi.

    One thing you could do is to check if the man is hitting the wall: if not, he will be able to walk, else he will stop.

    code:

    if (Key.isDown(Key.RIGHT)) {
    play();
    if (!this.hitTest(_root.wall._x+1, _root.wall._y, true){
    _x += movespeed;
    }
    }



    There are others ways to do this however. Try this one.

    Hope it helped.

    EDIT:

    code:

    if (Key.isDown(Key.RIGHT)) {
    play();
    if (!this.hitTest(_root.walls._x+1, _root.walls._y, true){
    _x += movespeed;
    }
    }


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