shooting a basketball arc, Pixel-based
Anyone know how to simulate the arc of a basketball while shooting? I'm using 16.16 fixed point. The ball when shot or moving has a vX and vY variable that is added to its x any y coordinate. The basket is at some point (b.x, b.y). Anyone know how to find the proper vX and vY amounts? This is pixel based so Moving the object by (1<<16) will move it one pixel.
-Thanks for any and all help.:)
This is where some simple physics will help.
Take the initial velocity and find the vertical and horizontal components. Then use the formula vf=vi+at where "a" is -9.8 and t is how many seconds have passed since launch/throw.
[Edit]
Forgot the negative.
Take the initial velocity and find the vertical and horizontal components. Then use the formula vf=vi+at where "a" is -9.8 and t is how many seconds have passed since launch/throw.
[Edit]
Forgot the negative.
I already know how to create the arc. I guess my question is how do I determine the correct xVel so that the ball ALWAYS hits the rim?
You need to tell some more about the physics you are using. The vX and vY are not constants or you would not be able to get an arc. So what do the vX and vY depend on? How are they calculated?
Then people can try to derive an equation and solve it.
Then people can try to derive an equation and solve it.
OK, but I'm using pseudo physics.
if(ball.shot){ ball.vX = someValue; ball.vY = anotherValue; // anotherValue is negative since the positive y-axis points down}ball.x += ball.vX;ball.vY += GRAVITY; // In this case, GRAVITY is positive to drag the ball downball.y += ball.vY;if(objCol(&ball, &rim)){ ... //take appropriate action here ...}
Those are accurate enough physics, so long as you're using sufficiently small fixed-length time steps. What you need is to use the equation of a parabola to solve an arc that goes through the ball's current location, the hoop's location, and a point somewhere in the air that makes the arc drop through the hoop at the angle you want, but not so high an angle that the arc's apex is overly high.
That's why this is called a firing "solution".
That's why this is called a firing "solution".
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement