Jump to content
  • Advertisement
Sign in to follow this  
canond

shooting a basketball arc, Pixel-based

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.:)

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 down
ball.y += ball.vY;

if(objCol(&ball, &rim)){
...
//take appropriate action here
...
}

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!