A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: more angle problems

Hybrid View

  1. #1
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139

    more angle problems

    ok this one seems to be a tough one. Well for me anyway

    is it possible to use angles to determine whether an object has passed another object. Have a look at this




    you see that this cannot work, also checking the axis seperatly wont work either. Because the same problem can occur, also note that gravity can effect the object, so the object can be released parallel to the center and might fall below the center before it visually passes the center

    any help?
    Last edited by mr_malee; 12-14-2006 at 08:26 PM.
    lather yourself up with soap - soap arcade

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    ok well this works, but the object must not be affected by gravity until it has passed, meaning its trajectory stays the same

    //rd = distance vector - floored
    //rel = inital vector - floored

    var passX = rd.x >= 0 && rel.x <= 0 || rd.x <= 0 && rel.x >= 0 || rd.x == rel.x;
    var passY = rd.y >= 0 && rel.y <= 0 || rd.y <= 0 && rel.y >= 0 || rd.y == rel.y;

    if(passY && passX) //reset gravity
    lather yourself up with soap - soap arcade

  3. #3
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    if you use localtoglobal to get the red balls position relative to the white ball then the red ball has passed through the white ball (or it's axis) when the sign of the X or Y has changed.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Just thinking out loud here, but maybe you could "rotate" the x axis, so that the ball is at 0,0 and the moving ball is along it, if it goes to negative it crossed.

    (The x-axis would be along the actual line drawn between, not the direction of movement)

  5. #5
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    i might try that out blink, UnkownGuy care to elaborate, i kinda got lost
    lather yourself up with soap - soap arcade

  6. #6
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Hm, can't you use the dot product of the velocity vector and the distance vector between the two object ( from the red ball towards the center ). If it's negative
    it will have passed it.
    Hope I didn't misunderstand the question?
    // Mazapán, my portfolio

  7. #7
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259
    I don't mean to be the simpleton but it seems like this problem can be resolved with a hitTest. I don't see any reason you can't.

    i also had a kid ask me about the accuracy of 2 points. I moded the code some. I may not be what your looking forbut I think it will give you the idea.

    Code:
    range = 40;
    closeness = 0;
    function onEnterFrame() {
    	pointcode();
    }
    function pointcode() {
    //this just makes the hero move for the test
    hero._x += 10;
    //checks to see if its in the radius well just the X
    	closeness = checkpoint._x-hero._x;
    	if ((arrow_._x>checkpoint._x-range) && (hero._x<checkpoint._x+range)) {
    		
    		trace("good");
    	}
    //checks to see a miss
    	if (hero._x>checkpoint._x+range) {
    		
    		trace("missed");
    	}
    }
    you could add the y to get the all around checking. You can make the range 0 to be super accurate. This code was used to help make a DDR game so I think its good, being that DDR is all about checking checkpoints .
    CEO OF

  8. #8
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    Quote Originally Posted by Kianis
    Hm, can't you use the dot product of the velocity vector and the distance vector between the two object ( from the red ball towards the center ). If it's negative
    it will have passed it.
    Hope I didn't misunderstand the question?
    thats exactly it, thanks Kianis works a treat
    lather yourself up with soap - soap arcade

  9. #9
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Quote Originally Posted by mr_malee
    thats exactly it, thanks Kianis works a treat
    Great Glad I could help
    // Mazapán, my portfolio

  10. #10
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    trying to grasp at what you're asking, you want to be able to do a hitTest succesfully against a bullet even when it travels really fast? i thought tonypa's covered this somewhere, oh well, let me think...

    you ever heard of slope-intercept? you should have

    slope=(dy-ry)/(dx-rx);
    yintercept=dy-slope*dx; //i think?
    if(Math.abs(yintercept)<=combinedwidths){
    if(dx/Math.abs(dx)!=rx/Math.abs(rx)){
    trace("pass?");
    }
    }
    i think that'd be good enough, unless ive gotten it wrong somewhere, my brain's gottin' all fogg-ed upp-ed

    btw malee, you're angle thing could actually be used for guard ai, if the angle difference is great enough, they would be like, hey!! very nice, they'd react to slow close objects or fast objects that were far away
    Last edited by trogdor458; 12-16-2006 at 09:02 PM.

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