Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

I am throwing a ball using this:

        double v, vx, vy, alpha, t2 = 0;
   if (Keyboard.GetState().IsKeyDown(Keys.Up))
        {
            alpha = MathHelper.ToRadians(60f);
            v = -1230d;
            vy = v * Math.Sin(alpha);
            vx = v * Math.Cos(alpha);

            ball2pos.Y = (float)((vy * t2) + (g * t2 * t2 / 2)) +  graphics.GraphicsDevice.Viewport.Height - ball2.Height;
            ball2pos.X = (float)(-vx * t2);
            t2 = t2 + gameTime.ElapsedGameTime.TotalSeconds; }

It works without a problem. It calculates the throw including the gravitation (g). vx is how much it moves per second on the X,vY the Y accelerration (running against gravity), v the strength of the throw and t2 the current time.

But I want to change the formula to throw the ball to a given destination. Say I want to throw my ball from 60 degrees to a target. How much "strength" do I need for it?

What would be the formula? I'm not really good at figuring out that and google doesn't give me what I want. To simplify let's assume that the Y of source and target are the same:

Given: Angle, SourceLocation, TargetLocation, Gravitation

Looking for: Strength

share|improve this question

marked as duplicate by msell, Nicol Bolas, Tetrad Jun 11 '13 at 15:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

If you have good mathematical abilities, then you can write out the equations for the balls position, substitute the vy and vx with v * cos or sin alpha, and try and solve it on a piece of paper, using simple symbols/letters to represent each variable to remove the clutter and messiness. Then after solving it for v (and subsequently t as well), you can put all the icings back on.

Sorry for this short answer, I might get back on this later.

share|improve this answer
    
Can you try to post the formula? I need to get back on this stuff. –  Robin Betka Jun 11 '13 at 13:12
    
Okay, I have it :) –  Robin Betka Jun 12 '13 at 8:52
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.