0
\$\begingroup\$

Im trying to create a method to calculate the fall time for an object using real formulas. Well I came up with this:

    public static double calculate_fall_time(float height) {
        final float GRAVITY = 9.81f;
        float h = (1/2)*GRAVITY*2;
        float h2 = GRAVITY/GRAVITY;
        double t = Math.sqrt(((2*h2)/GRAVITY));

        return t;
    }

Well I used to this website to compare the results but it wasn't the same. If I have 370 at the input then my program shows 0.4515 but the website is showing around 8,6 seconds.

Does anybody know how I can fix this problem? Thanks in advance :D

NOTE: I know that arcade physics are much more fun but my goal is to create a rather realistic game. Thanks for reading.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Where do you use your height parameter inside your function? \$\endgroup\$
    – DMGregory
    Jan 29, 2020 at 19:24
  • \$\begingroup\$ Wait a second... thanks. I will try adding it :D \$\endgroup\$
    – Leocat
    Jan 29, 2020 at 19:25
  • \$\begingroup\$ This is my new function: double t = Math.sqrt(2 * GRAVITY * height); It outputs something which looks similar to the value of the website (85.20211494220669) but it itsn't correct. (8.69) \$\endgroup\$
    – Leocat
    Jan 29, 2020 at 19:28
  • 1
    \$\begingroup\$ ...why are you multiplying by gravity? Higher gravity should decrease your fall time, not increase it. How did you derive this formula? \$\endgroup\$
    – DMGregory
    Jan 29, 2020 at 19:34

1 Answer 1

1
\$\begingroup\$

I have found a very simple solution to my problem. This is my code: double t = Math.sqrt(2 * height / GRAVITY); Thanks a lot! (ᴵᵐ ᵃⁿ ᶦᵈᶦᵒᵗ)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .