Thread: gravity effecting velocity

  1. #1
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Question gravity effecting velocity

    I got a problem with gravity effecting velocity.
    my gravity works like this:

    you.vl.y-=grav*speed; // the speed is for frame limting.
    you.pos.y+=you.vl.y*speed*3;


    Now lets say i wan't to change the y velocity so it will throw me up to 100. I can do this but what i want is to change the gravity and still have the velocity get me to 100.
    So how would i do this? I can't figer it out.
    int a; don't make a program without it.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    22
    I really have no idea what you're asking. But remember that the value of gravity is not a velocity but an accelleration.

    grav = -9.8 ///it's a constant. that's the ACTUAL gravitational constant regarding earth, but it would change for your program.

    velocity = -9.8t + initlvel //t is the amount time the object has been affected by gravity, initvel is the initial velocity the object has when it "jumps"

    ypos = .5(-9.8)t^2 + initvel(t) + initypos

    hope that helps! =) a little calc goes a long way...

    edit: errors

  3. #3
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109
    all i need is a that tells you how many meters sec you need to be moving to get 300 meters off the ground no matter what the gravaity is.
    int a; don't make a program without it.

  4. #4
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    all i need is a that tells you how many meters sec you need to be moving to get 300 meters off the ground no matter what the gravaity is.
    Well, getting to 300 meters is going to be dependent on the variables (gravity, velocity, etc...). Try looking at SmashBro's post again, because it is explained fairly well in it.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    22
    Okay I think I know what you want now.

    Just make gravity a negative number. We'll call it grav.

    If you shoot something straight up into the air and it gets to 300 meters exactly, then at 300 meters, the velocity is 0.

    So if we take the scenario that if you drop a ball from a 300 meter tall building, if you find the velocity of the ball when it hits the ground, that's the same velocity you need to shoot it up into the air with, since grav will always be constant.

    finalypos = .5grav(t^2) + initvel(t) + initypos

    The final ypos is 0, when the ball hits the ground. grav is whatever negative constant you want it to be (as you requested.) t is the time it takes for the ball to hit the ground; it's what we're solving for.

    initvel is 0--because at the moment you let go of the ball from the top of the building, it has no velocity. initypos is 300 meters.

    So then we have

    0 = .5grav(t^2) + 0 + 300
    -600 = grav(t^2)

    -600/grav = t^2

    t = sqrt(-600/grav)

    That looks complicated but if you had a constant for gravity, it would just be one number at this point. Anyway, that's the time that the ball would have a positive velocity after you throw it up. We can plug this nuber into my previous velocity formula:

    velocity = grav(t) + initvel //initvel is 0

    velocity = grav(sqrt(-600/grav))

    So, there's your answer. Or, for any verticle distance the formula would be...

    velocity = grav(sqrt(-2desiredheight/grav))

    Of course, if you don't understand exactly how all of that works, the formula isn't going to help you as far as creating video games goes. And if you didn't understand any of that at all, then I suggest taking calculus and physics before getting into that kind of programming, because it definitely helps. =P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Velocity in rotation using 2D vectors???
    By blackCat in forum Game Programming
    Replies: 1
    Last Post: 04-10-2009, 09:16 AM
  2. Platform game gravity problem
    By Akkernight in forum Game Programming
    Replies: 33
    Last Post: 02-22-2009, 01:10 PM
  3. orientation from velocity
    By ichijoji in forum Game Programming
    Replies: 2
    Last Post: 08-28-2005, 07:22 PM
  4. Need help with gravity engine
    By madmech in forum Game Programming
    Replies: 11
    Last Post: 07-03-2005, 02:41 PM
  5. Velocity vector troubles
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 01-18-2005, 11:40 AM