A Flash Developer Resource Site

Page 3 of 11 FirstFirst 1234567 ... LastLast
Results 41 to 60 of 215

Thread: The elusive hitTest explained

  1. #41
    Senior Member g_M_e's Avatar
    Join Date
    Jun 2002
    Posts
    147
    my question is a hitTest question.I have rounded corners in my hitTested MC and pacman and my ghost are getting caught up on them.

    You can check it out (swf, fla, as) here, PACMAN
    g_M_e

  2. #42
    Junior Member
    Join Date
    Dec 2002
    Posts
    29

    One of the original questions, still unanswered.

    Everyone has been really helpfull here it seems. Very cool.

    Sadly, the question I came seeking an answer for was asked early in this thread, but the answer was side stepped.

    I want to test the hit of two non box non circle movie clips. Anyone got a solution for this.


    There's a:
    anyMovieClip.hitTest(x, y, shapeFlag);

    and a:
    anyMovieClip.hitTest(target);

    Why isn't there a:
    anyMovieClip.hitTest(target, shapeFlag);

    that would have been so nice.

  3. #43
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361

    Re: One of the original questions, still unanswered.

    Originally posted by homeDrone
    Why isn't there a...
    because it would be too hard for the already slow flah player to compute. Director can do it with matte clips, but sadly, flash cannot.

  4. #44
    Junior Member
    Join Date
    Dec 2002
    Posts
    29
    I hear ya. I was thinking about it the other day and that's what I figured the answer would be.

    I came up with a bit of a comprimise solution though and am in the process of coding it now. Though, my skill is not tip top, so it's going a little slow. I've hit some bumps I didn't anticipate.

    My solution was to attach a couple movie clips with nothing in them to my objects at key points (corners ect.) Then just test the x and y coordinates of those clips to the target shapes. Im having some problems with getting the right coordinates from the embeded movie clips. As you might guess if I call for the _x position of a one of them, it gives me the _x postion relative to the parent clip, not the screen area.. so I have to work backwards to get the right coords. Even scaling the parent clip changes things and I have to work that into the calcs. Bit of a hassle.

    If I am successfull before I get bored of it I'll let ya'll know.

  5. #45
    Not PWD ViRGo_RK's Avatar
    Join Date
    May 2001
    Posts
    1,799
    I tried that once. I got bored after typing

    Code:
    if this.hittest(_root.thinger) {
    
    }
    I have a short attention span

    Chicken, hmm, chicken.

    Ohh, mommy! Fire Engine!

    There's a three legged antelope on the roof...


    PAlexC: That's just Chuck Norris's way of saying sometimes corn needs to lay the heck down.
    Gerbick: America. Stabbing suckers since Vespucci left.

  6. #46
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Thats a common solution homeDrone, one which works pretty nice with racing games having 4 hit points on the 4 corners of the car for collision detection. It isnt an exact shap to shap test, but when dealing with only 4 points, its not really a big deal.

  7. #47
    Junior Member
    Join Date
    Dec 2002
    Location
    Milky Way
    Posts
    5

    Please check this out and tell me what I am doing wrong...



    Want to be my "Hero-of-the-Day"(tm)?

    I need some serious help. I understand the way that the .hitTest() method works, but I cannot get to it work the way I want it to.

    Here is the .swf: http://www.markcoates.com/testEngine.swf

    I got the movement of the "avatar" working the way I want it, but I need the collision detection to do a few more things.

    1) The avatar should be completely unable to move through objects (such as the gray square).
    2) It should not get "stuck" like it does when it gets caught in the
    .hitTest() area.
    3) If you hold the mouse button down, it should *still* be unable to move through objects.

    Can someone please take a look at the .swf and the source and help me see what I am doing wrong or what I need to add to get the desired functionality?

    Thanks once again. I am indebted!
    Attached Files Attached Files
    .'.NodeRunner.'.

  8. #48
    Senior Member g_M_e's Avatar
    Join Date
    Jun 2002
    Posts
    147
    Here is what i did. My example is a mod of your FLA, but I didn't use the mouse i used keyboard input. The AS code is what I'm going to use for all my projects. It is provided in original form by the Great Ed Mack (w00t! via los Eds!).

    Ed Mack's code works great, except for when you have a wall with a thickness/width smaller than your object! So first we test the bounds of the boxes for corner hits then we test from the origin. Seems to work great for me. Take a look the modification i made to your FLA. If you select your avaContainer MC you 'll see the code I've added. Tweak it to your delight (make it work for mouse events and bring it in a little closer to the wall). It took me a second to figure it out, but I'm sure you can too.

    HOPE THIS HELPS!
    Attached Files Attached Files
    g_M_e

  9. #49
    Junior Member
    Join Date
    Dec 2002
    Location
    Milky Way
    Posts
    5
    Thanks everyone for all the help. I got it working (a la Ed Mack) and I am pleased with the results. My game engine is well on its way now. The fun part begins!
    Last edited by NodeRunner; 12-20-2002 at 05:27 PM.
    .'.NodeRunner.'.

  10. #50
    Actionscript Nerd
    Join Date
    Apr 2002
    Location
    USA
    Posts
    47
    woo! can't wait to see the finished game!
    ••••••••••••••••••••••••••••••••••••••••••••••••••
    Try out the all new Ball Drop 2.0!
    http://www.mtsu.edu/~jwt2h/balldrop/

  11. #51
    Junior Member
    Join Date
    Dec 2002
    Location
    _root.home.room.chair
    Posts
    23
    Originally posted by strangelife2k
    I am going to show you how to have a hitTest on your badguy so that if your hero touches it, it will decrease your life.

    1.Goto your hero's instance box and name it "player"

    2.Add a dynamic text box on your scene, and set it's variable to "life".

    3.Add this code to Frame 1
    Code:
    life = 100;
    Edit the life if you wish

    4.Bring up the object actions panel for your enemy and add these actions:
    Code:
    onClipEvent (enterFrame) {
        if (this.hitTest(_root.player)) {
            _root.life -= 5;
            if (_root.life == 0) {
                _root.gotoAndStop(2);
            }
        }
    }
    These actions cause the variable "life" on _root (the one you set the dynamic text field to display) to go down by 5 each time the player and the enemy collide. It also makes the main timeline goto frame two, if the player runs out of life. You should put a gameover screen on frame two of _root.

    There you go, test it out

    [ed: Just tweaking a few readability things, thanks very much for this ]
    Hi.

    Thanks for the example strangelife2k. I just have a question about it. I got it to work so that it deducted from the life variable every time you touch the enemy but instead of using a frame number for the game over screen, i used a frame label called "over". I could not get the game to go to the game over screen when it reached 0 and i thought i'd try changing the location that the movie should go to to "2" and it worked. Any ideas why frame labels don't seem to work for this kind of thing.

    As you can see, i'm pretty new to flash.

    Thanks


  12. #52
    Junior Member
    Join Date
    Jun 2002
    Posts
    21
    Ahrrrrg!!!

    Why is this not working?

    oh, and a Merry Christmas to everyone at Flash Kit!!!

    Ho Ho Ho
    Attached Files Attached Files

  13. #53
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    I need the code to detect a hitTest between two duplicated movieclips that are the same. e.g to enemy cars.

    When i try to make the code myself the cars run the code for themselves. (sounds confussing!) What they are doing is running the hitTests against them aswell as any other movieclip with the same name. e.g _root["ecar"+i].

    Please help me
    lather yourself up with soap - soap arcade

  14. #54
    Escape artist condorcet's Avatar
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    133

    edge to edge collision detection

    hi
    is there a way to do edge to edge collision detection of two movie clips? I am trying to detect when my first MC hits my second one but the clips might be on a diagonal angle and so i need to use the actual MC and not the bounding box. I tried using true but it doesn't work. Basically i have a MC you can drive around and another which is a shed. I want to park in the shed but only through the open door. If you hit the wall i want the first MC to stop. But the shed is on and angle and so the wall is angled. How do I get this to work?

    if i put little boxes on my first MC then that works but not on the diagonal walls?!

    thanks anyone
    You can't have everything...where would you put it?

  15. #55
    Junior Member
    Join Date
    Dec 2002
    Posts
    29
    I know the theory of what to do, but I don't have code I can just give you yet.

    As senocular says, it's apparently a common solution for the problem, but no one eles has yet posted some freebe code for it here either. (^_-)

    In you car movie, put an object (an empty movie clip will do) at each corner. Then do hit tests for those 4 objects center points and your garrage. Since it's just a coordinate set and not a clip you are doing the hit test with, you can use the "true" setting on the hit test.

    The problem I'm having with this, is that the coordinates that you get when you call from the embeded corner clip are relative to the car movie clip. It seems that the hit test wants absolute screen coordinates (does that make sense?) so you have to calculate that by adding or subtracting the coordinates of your car movie clip.

    EG:
    car clip center is at 50,500 in the main movie clip.
    embeded corner clip is at 3,8 in the car clip.
    so the corner is really at 53,508 in the main movie clip.

    That's my guess anyway. I still havent got it working yet.. so I could be wrong.

  16. #56
    Escape artist condorcet's Avatar
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    133
    my big drama is that if i put little squares say at the edges of my objects it will work but i am testing for a lot of things - corners of the car object, corners of the objet being towed, walls of the garages and so on. This means that i would run this function (to test for hits) about 200 times each frame and that makes it too big and chunky to work properly. If there is no way to do this then i wil give up and do it more simply but i thought maybe someone out there would know a workaround??
    Last edited by condorcet; 01-12-2003 at 06:21 PM.
    You can't have everything...where would you put it?

  17. #57
    Junior Member
    Join Date
    Dec 2002
    Posts
    29
    I hear ya. I will have the same problem I think. But on the example you showed me, you'd only have to test for about 4 points on the jeep and maybe 5 or 6 points on the chopper. You don't need to put any points on the buildings cause they won't be moving.

    As far as I can see, using little corner objects IS the workaround when dealing with movie clip hit tests without bounding boxes (;_;)

  18. #58
    SaphuA mosterdfles_flash's Avatar
    Join Date
    Jan 2002
    Location
    Tha Couch
    Posts
    935

    AAARRRGGG

    GEEZ!!!

    JUST LOOK A FEW PAGES BACK!!!
    'How Art Is The Visual While We’re Artificial…'

    Mail & MSN
    My Not Finisched Page!
    Nick: SaphuA

  19. #59
    There Were No Good Names Left
    Join Date
    Dec 2002
    Location
    Edge of a building
    Posts
    118

    Hittest for a game

    I've been working on this one part of my short game in which dynamic text tells how many times the ball has hit a certain movieclip on the stage. I just can't get it to work. I've consulted tutorials, help in flash, and I can't figure it out. I sent my fla with this letter. Could someone please take a look and try to help? If you find the problem could you fix it? I have no idea. The actionscript I'm mainly having trouble with is hittest, target paths and dynamic text. Please someone! I'm quite new at this.
    If you can't be bothered downloading it, then heres the situation. I'm getting some dynamic text to tell how many times you've hit a ball. I figure the only way is to use
    if(this.hittest(_root.ball));
    _root.p1=_rootp1+1
    Telltarget(_root.ball)
    Play;
    p1 is the var for the dynamic text box, all the actionscript is under the actions for the bat that hits the ball, and _roor.ball is the target path for the ball.
    It dosen't seem to work. I also write a few frames earlier that _root.p1=0
    If you can help me from all that, please do, but please download the fla. to get a better look. (I probably made a typo somewhere)
    Attached Files Attached Files

  20. #60
    Senior Member
    Join Date
    May 2001
    Posts
    198
    You wrote the code like this:

    Code:
    if(this.hittest(_root.ball));
    _root.p1=_rootp1+1
    Telltarget(_root.ball)
    Play;
    It should be written like this:

    Code:
    if(this.hitTest(_root.ball)){
    _root.p1=_root.p1+1
    tellTarget(_root.ball){
    play()
    }
    }
    Bring Back The Flash Footers Goddammit.

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