1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Find the amount of gravity?

  1. Jan 10, 2013 #1

    I'm new to this forum, and I signed up because I have been struggling with this problem for a couple of days now.
    I am making a game where the player has to land on specific platforms.

    The player runs at 4 meters / second.
    When the player jumps there are 4 different platforms to land on.
    All platforms are 50 centimeters apart, each.
    1 jump covers a distance of 2 meters. ( Hence the 4 platforms to land on each jump. )


    2. Relevant equations

    I currently have the following equation to solve the problem:

    abs(sin(0.5 * PI * x))
    I enter the distance at x. And it returns the correct height.

    In theory, this works, but in game I have to keep applying gravity etc.
    How could I possible make the player jump this curve when applying gravity?

    I have 0 knowledge of physics or whatsoever.
    Never had any good math lessons at school so I suck at this topic.

    I hope I was clear enough.
  2. jcsd
  3. Jan 10, 2013 #2


    Staff: Mentor

    so are you assuming the jumping arc is a sin curve? If so thats an interesting solution to get an arc but in reality a jumping curve in a constant gravity setting with no air resistance (like the Earth's surface) is a parabola.

    Perhaps that is the source of your problem. The wki article below describes these kinds of curves.

  4. Jan 10, 2013 #3
    Like I said, I have 0 knowledge of physics.
    Thats why I took a Sin curve. Because it is always accurate to what I need.

    I need help converting it back to gravity. But I have no Idea how much upforce I have t apply and how much downforce I have to apply.
    That is why I posted my question here.

    Thanks for the link; reading the page as we speak. :)
    Last edited: Jan 10, 2013
  5. Jan 10, 2013 #4
    Well, the simple answer is you can't make the player follow this curve by following gravity since, as jedishrfu said, projectile motion follows parabolas not sine curves. If you're willing to adapt the game design so that the platforms are along the correct type of curve, we can help you—but if you're sticking with a sine curve, we can't help you with "converting it back to gravity" because that's not what gravity does.
  6. Jan 10, 2013 #5


    Staff: Mentor

    Your sin curve and parabola share a lot of common features so that switching shouldn't be a problem.

    The way most game physics works is that they numerically integrate a simple formula to get the parabola. Starting at a given position with a given initial velocity

    vx = vx0 * t
    vy = vy0 - g * t
    x = x0 + vx*t
    y= y0 + vy * t
  7. Jan 10, 2013 #6
    I could change the curve, no problem.

    Tho the platforms have to stay 50 cm away from each other, in height it doesn't matter.

    Thanks for all the help I'm getting. Reading through the Wiki, but I barely know how to read those formulas..

    Mind confirming if I have done this right?

    Velocity = 20.
    Angle = 45.
    Gravity = 9.81.

    d = ((20^2) * sin(2 * 45)) / 9.81.

    If I solve it like that, am I doing this correct?
  8. Jan 10, 2013 #7
    I'm sorry but I do not know how to read that.
    Are there any books on how you solve equations like that?

    Like I said in the first post, I have 0 knowledge on how to read formulas.
  9. Jan 10, 2013 #8


    Staff: Mentor

    Here's a simple processing script (processing.org) to try out:

    Please note that 0,0 is the top left corner and that I used a reverse sense to the vy0 and the g (gravity) values. The float values can be considered to be in meters:

    Code (Text):

    float x,y,vx,vy;
    float x0,y0,vx0,vy0;
    float g,t,dt,r;

    void setup() {
      size(640,480);  // setting screen size


      vx0=50.0; // 50 meters / sec
      vy0=-50.0; // 50 meters/sec

      g=9.8;  // g in meters/sec/sec



    void draw() {
      t = t+dt;

      vy=vy0 + g * t;

      x = x0 + vx * t;
      y = y0 + vy * t;

    Last edited: Jan 10, 2013
  10. Jan 10, 2013 #9

    (Don't leave out your units like m or m/s when substituting things into equations, they're important!)

    That formula gives you the maximum range of a projectile launched with initial speed v at angle 45 due to gravitational acceleration g. Since you know the maximum range you desire (2m), you've picked 45 degrees as the launch angle, and you seem to be sticking with the acceleration of real gravity that means you have to solve for initial launch speed, ##v_0## (which you wrote as ##v##, but ##v_0## is better since it's just the initial speed).

    Now having determined all your projectile parameters, what you want is the equation for the trajectory given here:
    ##y = \tan(\theta)\cdot x - \frac{g}{2v_0^2\cos^2(\theta)} \cdot x^2##
    where y is the height as a function of distance x, ##g=9.8m/s^2##, θ is whatever you chose for the launch angle (45 degrees in your example), and ##v_0## is what you calculated above. By calculating this at x=0.5m, 1m, 1.5m, and 2m, this will tell you how high to put your platforms.

    Now I'm assuming your game has a time parameter and so you will want the avatar's position to be a function of time. For this, you want what are called the parametric equations for projectile motion (given right above the trajectory equation in that same link), and they are:
    ##x(t) = v_0\cos(\theta)t##
    ##y(t) = v_0\sin(\theta)t - \frac{1}{2}gt^2##
    (or you can just calculate x(t) and then plug that into the equation above for y as a function of x).

    And that's it! If run into trouble doing this, just ask—but do be specific in your questions so we can help.
  11. Jan 10, 2013 #10
    "Give a man a fish..." jedishrfu. This isn't helpful in the long run (and is against forum rules).
  12. Jan 10, 2013 #11
    All this said, it's worth pointing out that someone following this trajectory would, depending on your exact horizontal placement of the platforms, always: (i) miss them all and just land two metres ahead, (ii) hit their head on the first platform, or (iii) land on the second or third platforms. The same thing will always happen, as they would have no control over where they land if they always jump along this fixed trajectory. Projectile motion is deterministic.

    This is why avatars generally don't follow projectile motion in games. If you think of a game like Super Mario, you are able to control the character while they're in the air. This lets you decide where you want to land. In true projectile motion, you don't have a choice once your feet have left the ground.
  13. Jan 11, 2013 #12
    Thanks for the description above! I will try to put it in my game.

    And yes, I know that the character will have no control, but thats the whole point.
    The game I'm making is a one button game, the player can only tap the screen of the phone to make his player jump.
    Thats why the jump has to be fixed.

    Also the collision only works from the top side of a platform, so this way the player can't bumb his head (Think about mario), but can jump again from the platform he just went through.
  14. Jan 11, 2013 #13
    I see, so the character will stop on each of the platforms along the way? That changes your scenario quite a bit. If the avatar jumps and lands on the first platform and then makes the exact same jump again (i.e. same initial velocity) it will not continue along the same trajectory as before. It follow the same shape trajectory but from the new starting point.
  15. Jan 11, 2013 #14

    Here is how the game works:

    The character has to jump on these platforms.
    He can only tap the phone screen, and the character jumps.
    Each platform will play a beat.

    Because we want to be able to move the platforms closer to each other, we have to also increase their position on the Y axis.
    This way, we are able to catch the player mid air, and the player is able to jump again from that platform.

    He is constantly moving at a speed of 4 m/s so you need a pretty high reaction speed to play the game.
    But that is what the game is about.

    Hope that explains the situation.
  16. Jan 11, 2013 #15
    I see, that makes sense—so in your original drawing, those were just possible locations of the platforms.

    Note, though, if you are requiring a constant horizontal speed of 4m/s then you no longer have the freedom to choose the horizontal velocity in the above equations. The only parameter you would be free to adjust is the strength of gravity (g in those equations) to get the 2m range you want.
  17. Jan 11, 2013 #16


    Staff: Mentor

    Cant you instead adjust the vertical velocity?
  18. Jan 11, 2013 #17
    As long as he's fine with giving up the 45 degree jumping angle, which their might be aesthetic reasons for. But yes, either the angle or the gravitational acceleration will need to be adjusted if the horizontal speed is to remain fixed.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook