A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: where will it bounce?

Hybrid View

  1. #1
    Member
    Join Date
    Nov 2006
    Location
    on the face of the earth, on the steps
    Posts
    74

    where will it bounce?

    I'm making a 3D tennis game, and I'm trying to make a little indicator circle that will appear on the floor of the court at the location where the ball will bounce

    my initial height is how high the ball was when it was struck, but here's where it gets tricky

    y=360 is the floor of the court, so that y=0 is actually 360 pixels above the court

    and I guess if you were to just turn my tennis court sideways temporarily, the z-axis movement (into and out of the screen) would become the x-axis for the purposes of solving for y=0 (y=360...)

    I'm pretty sure I can factor out time - at least I'll try it, but at any rate, my fps for the movie is 46, and I've got the gravity at 1, which decrements (increases because of flash's inverted y-characteristics) the height of the ball each frame

    I don't know how close to actual gravity 46 pixels downward each second would be with a scale of 15pixels = 1inch, but when I play the movie, it appears pretty lifelike

    also - the y-velocity would be something around -20 to -30, depending on the z-velocity of the shot (faster = lower b.ymov to keep the ball in bounds)

    just for approximation's sake, a y-velocity of 25 would correlate to a z-velocity of around 180 or so

    At any rate, I'm not familiar enough with physics yet to know how to do a quick&dirty flash version of the projectile/parabola thingie so I know where to have flash put the circle on the ground

    can anyone help me out with this? I'd really appreciate it!!!
    Last edited by Seanx; 01-15-2007 at 01:21 AM.

  2. #2
    Member
    Join Date
    Nov 2006
    Location
    on the face of the earth, on the steps
    Posts
    74
    I don't know if any of that made sense to anyone, so I just drew up a pictorial example in paint and attached it here
    Attached Images Attached Images

  3. #3
    Member
    Join Date
    Nov 2006
    Location
    on the face of the earth, on the steps
    Posts
    74
    I suppose I could create new variables based on the x, y, and z motion vs. the current x,y,z positions and decrement them in a for loop until y=0, and then get the new coordinates, but that's like breaking the sound barrier or something for me

    well, I'm so new to programming, every new thing I figure out feels like a major accomplishment.

    jbum - I'm a big fan of your site - it was your bestiary containing all of those cool flash movies/games with so few lines of code that made me realize I could maybe make some cool games (kisses up to moderator hoping to get a faster response)

  4. #4
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Hey sean,

    Seems like you're pretty eager to get this thing working, so let me get right to it

    If there's no gravity in your game, this is going to be quite simple:

    using the equation
    xf = xi + v*t

    we can figure out the amount of time it'll take the ball to get to a certain position. All you need to do is plug in xf(target position), xi (initial position), v(the speed of the ball) and solve for t. Let's do an example:

    Let's say we wanna know when (and where) the ball will hit the floor. to do so we can modify the above equation like so:
    t = (xf-xi)/v

    and since we're checking collision with the floor, we'll use y instead of x:

    t = (yf-yi)/v

    so in your code you would plug in the following:

    Code:
    fps = 46 //or the current frame-rate of your movie
    
    yf = 360 //position of floor
    yi = ball.y //current position of the ball
    v = ball.speed.y*fps //y component of the speed of the ball per second
    
    t = (yf-yi)/v
    ok, so now we have the exact amount of time from now at which the ball will hit the floor.. all we need now is the x and z positions of the ball at that time. We can get those using the same equation:

    xf = xi + v*t

    so in code it would look like this:

    Code:
    ballHitX = ball.x + ball.speed.x*fps*t
    ballHitZ = ball.z + ball.speed.z*fps*t
    so there you have it, the position where the ball hits the wall is

    (ballHitX,360,ballHitZ)

    I hope this guides you in the right direction, let me know if you have any questions
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  5. #5
    Member
    Join Date
    Nov 2006
    Location
    on the face of the earth, on the steps
    Posts
    74
    I'm pretty sure that will do the trick, although my game does have gravity - you've given me enough to get underway - I'm at work right now so I can't try it out, but I just wanted to thank you for your very detailed post - always appreciated !! thanks again
    Last edited by Seanx; 01-16-2007 at 07:13 PM.

  6. #6
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Hey! Please see this game published in flashkit.
    http://www.flashkit.com/movies/Games...0917/index.php
    <signature removed by admin>

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