A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Tricky maths question

Hybrid View

  1. #1
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796

    Tricky maths question

    First off, thanks to Malee and co for solving my arrow rotation problem before- working great now.


    I've been stumped by something else now. Maths never was my strong point in school.

    Check out the example pic. As you can see, the archer fires the arrow into basically a wall mc.
    TARGETA= invisible bounding rectangle within the target stand that runs hitTests for the arrow and stops it when it lands.
    TARGETB=frontal perspective view of the target.

    What I want to happen;- the arrow hits TARGETA and then a hole (black circle mc) appears somewhere on TARGETB to represent approximately where it has landed.
    In code-
    - There's no real z depth to the arrow so I'll have to randomize the x position on TARGET B. But the arrow hits TARGETA mc at a certain _y position so I can then use that _y value to estimate a _y position for the hole mc.

    So my question is how do I transfer the y position of the arrow to a suitable y position on TARGET B mathematically? TARGET A and TARGET B are both different heights, and also the target stand is at random locations so I'd have to do something about it's x position.

    Like, convert all the mcs to global x,y and targeta._height-targetb_height+arrow._y?
    Tried all sorts but nothing is working accurately right now.
    Last edited by EvilKris; 08-25-2007 at 03:33 AM.

  2. #2
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    Lets say arrow._y = 0 where the arrows point is. if arrow mc and targetA mc is at the same level, you can do this:
    Code:
    //find the relative y-distance down on targetA
    relY = (arrow._y-targetA._y)/targetA._height;
    //attach a dot-mc to show where you hit, name "dot", inside targetB-mc.
    dot._y = relY*targetA._height;
    dot._x = random(targetA._width);
    That should do it
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

  3. #3
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    Nice one Norweigan dude!

    Working quite accurately now and I was even able to recreate a sort of z depth for the arrows which works on how deep they penetrate the hitTest mc.
    Looking quite sexy now. I'll post the Archery part of UltraSports in about a week, after I get the two player action up and running.
    Kris

  4. #4
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    Your welcome

    Looking forward to see it in action
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

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