-
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!!! :)
-
1 Attachment(s)
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
-
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)
-
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
-
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 :)
-