Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Formula to fly up to a point at different speeds

  1. Jun 21, 2012 #1
    Hello,

    I'm trying to build a game that has birds fly up on the Y axis (I'm ignoring the X axis for now).

    What I'm trying to achieve is for the the birds to fly up against gravity (in this case set to 240) to a predefined height and at different speeds.

    E.g. Bird1 flies up 400 pixels at a speed of '10'. Bird2 flies up 400 pixels at a speed of '5'.

    The variables I can set is 'velocity' and 'acceleration'. I have a gravity factor of 240 trying to push the birds down at all times.

    What formula would I use for this?
     
  2. jcsd
  3. Jun 22, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey harleyon and welcome to the forums.

    If you were to use a force framework for physics, what you can do is to create a force vector that always down (i.e. towards the earth). So for 3D it would be towards the negative y-axis.

    If you are able to have say a scene where you can 'fly around the earth' then the force vector should point towards the centre of your virtual world: if its flat don't worry about this.

    Then for specifics you need to do unit conversion and find the right parameters. The reason is that in games, we don't use 9.8m/s even if the units with respect to the perspective and size of the characters and other objects is right.

    So you will need to figure out a ratio for screen units with respect to metres and then specify a coeffecient for your gravity. The force vector then given that positive y points 'up' will be (0,-g * scaling) where the g is your coeffecient for gravitational force and scaling is your scaling calculation to convert metres into game units.

    What you do after this is that the bird supplies a force to overcome the gravity and that force will usually depend on the direction of flight from the user. You can (and this is why its better to have this system), add as many forces as you want for things like aerodynamics if you want to add this later.

    Once you have this force system, you end up taking all the forces on the object and then you add them together to get the net-force. You then integrate this force into the object itself and it will move in that direction.

    You will also need to supply a mass for the bird. Then what happens is you take all of this and you get the momentum over time for the bird and the velocity component is what you use to move the bird.

    The momentum is calculated as the integral of the force. Basically what you do is you have a small time value and the momentum increases by F * dt = mv (v is velocity which is a vector). Then given that you know the mass, you then take the velocity and increase the displacement of your object by v * dt (i.e. add this to your velocity) to get your position of your bird and keep doing that each frame of your game.
     
  4. Jun 22, 2012 #3
    ... in the meantime :smile:

    the additional acceleration is given by

    -(u2+2.g.s)/2s)

    where u is initial speed, g is background 'gravity' and s is the height.

    I think your bird is going to be flapping for a long time, though.
     
  5. Jun 22, 2012 #4
    Great - thanks guys. I'll give it a go.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Formula to fly up to a point at different speeds
  1. CMD Dosent Pop Up? (Replies: 4)

Loading...