A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: What's the best method for hitTesting ground and shapes in a platform game?

  1. #21
    more now more
    Join Date
    Sep 2005
    Location
    Brighton, UK
    Posts
    80
    no probs, just give me a shout if you change your mind.

  2. #22
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    If your still not pro using lots of movieclips or math, I have another suggestion.

    As you are currently using point collision, keep using that, but with a lot more points in the horizontal and vertical direction.

    So if your max speed is around 5, you would test for points at the bottom, bottom+1, bottom+2, bottom+3, bottom+4, bottom+5(down). So, if you loops through the bottom one first, if it doesn't hit, break the loop and stop checking.

    But if it does hit, go to 4 below the bottom of your character. If that one doesn't hit, you know that 5 pixels down is the ground. Likewise, if 4 hits, and 3 below doesn't, the ground is 4 below.

    So when you modify the y the next time, whatever you found the distance to ground to be, make it the maximum allowed to be moved. (Math.max(distanceyfound, speedy)).

    You will probably have to do that idea I showed you eight times. Twice from the bottom (left and right), twice from the right (top and bottom, going out right), twice from the left(top and bottom, going out left), and twice from the top(left and right of character, going up).

    This isn't a perfect solution and may end being more work, haven't tried. (There may be a problem if the x amount of you move, changes the platform the y would detect against, but I'm not sure how much of an issue that would be. Also, if you keep the speed to integers, it should look fine).

    If you want more explanation, just ask.

    Hope that Helps!

  3. #23
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,651
    Been trying to fix the bumping problem for a while now, it just wont go away. It only goes away when removing the code Squize added.. but then he falls into the ground and slowly moves to the surface....

    what do you mean with "with a lot more points in the horizontal and vertical direction."?

    Don't get what these "points" are , sorry.

    Try to explain in detail (if possible) how I can make the collision work better. Or modify my fla or code so it works and I'll look and learn from that; that would be the easiest way for me to see how things is supposed to be to work.

    Also, "integers" is that whole numbers?..... like 22, but not 22.5?.. so using 22 is better as it's more accurate? is that what you are trying to say?

  4. #24
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    Regarding the integers, I mean if you want your character to be precisely on top(and assuming you keep your platforms top and bottom to integers).

    By points I mean are the points you use the shape collision detection against.

    So the more frequent the points are the more precise it is, but more processing power it takes.

    So you draw points(by draw I mean test the points ) up to where your character will be next frame, find out which point is the farthest the hero can go without hitting and stop there.

    If you need a diagram, I may be able to make one tomorrow.

    Hope that helps!

    (Goes and plays starcraft)

  5. #25
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,651
    Still dont understand (I do have a clue what it could be, but not sure) .... maybe make a code example?

    edit:

    Looked up the word "integers"
    (Pronunciation Key)in·te·ger Listen: [ nt-jr ]
    n. Mathematics

    1. A member of the set of positive whole numbers {1, 2, 3, . . . }, negative whole numbers {-1, -2, -3, . . . }, and zero {0}.

    2. A complete unit or entity.
    Ok, that's what I thought.. whole numbers, like 22, but not 22.5. That the explanation I wanted for that question .... still don't understand points and how to check them...... so make it code wise if you can as that probably is easier to understand and see what you mean.

    Thanks.
    Last edited by Ironclaw; 05-01-2006 at 03:25 AM.

  6. #26
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,651
    Oh, if I only had a working platform engine that I understood.

  7. #27
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    Oh, if only I had a girlfriend that I understood.

    Squize.

  8. #28
    waiting for the fallout
    Join Date
    Mar 2002
    Posts
    49

    Ironclaw Is The Bomb!

    Hey Ironclaw...

    Great Coding!! I have been attempting to make a Mega-Man style platform game and the source code that you included (Arghh3.fla) is just the example I have been looking for to get me started in the right direction. The code is simple and straight forward enough for even the most basic of actionscritpers to understand. Thanx a bunch.

    But I do have one question. The levels I am creating are a little more complex, moving on the y axis as well. Can you suggest a modification to the AS code of Arghh3.fla that would allow the _y property to change when the playerMC has reached a certain _y point (say 400 px) and then stop when the player is back in the middle of the screen?

    I have tried to modify it myself say:

    if (player._y > 400){
    world._y -= worldSpeed;
    }

    but when I do that, the worldMC continues to scroll up and up and up. HOW DO YOU STOP THIS CRAZY THING!!! either there needs to be a localtoGlobal function in there or maybe some loop that will break when the player reaches a certain y level. But as you can see in the fla file I have included, I have a trace on the playerMC's _y property, and when I put that slice of code in there, it doesn't change.
    Attached Files Attached Files
    If you were me, you'd be home by now

  9. #29
    waiting for the fallout
    Join Date
    Mar 2002
    Posts
    49

    Eureka!!!!

    I think I might have figured out how to stop the invisible elevator problem. If any of you were having the same problem, where the heroMC would rise up the side of the worldMC when it came in contact with the left or right of the worldMC, this is for you.

    I added couple of If statements to the heroMC stating:

    if (world.hitTest(heroMC._x + 10, heroMC._y - 10, true){
    heroMC._x -=10;
    }
    if (world.hitTest(heroMC._x - 10, heroMC._y - 10, true){
    heroMC._x +=10;
    }

    These two statements declare that if the heroMC's right side (+10) comes in contact with the worldMC then move the heroMC 10 to the left (-10). and vice versa. I also think the "moveup" if state was causing some problems so I changed it from:

    heroMC._y--;

    to

    heroMC._y = heroMC._y;

    Of course my heroMC may land into the platforms a little bit, but there is no sinking and if I jump up (if it's really bugging me, which it isn't) I'll be on top of the platform once again.

    I hope this helps in the grand scheme of things.
    If you were me, you'd be home by now

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