A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: But is it really gravity?

  1. #1
    Senior Member pitchdog's Avatar
    Join Date
    Sep 2002
    Location
    Rochester, NY
    Posts
    128

    But is it really gravity?

    Ok, if A = 1/2(gt^2), do any of the gravity balls & affects simulate the acceleration due to gravity?

    Some animated "gravity" objects seem to have a constant v, and I think other people have, indirectly, pulled it off. Anyway,the velocity of a gravity ball increase w/ respect to time. The ball should start out really slow and accelerate.

    Here's part of a simple enought formula I've tried.

    I set the gravity to .98 and it runs at 50 frames / sec.
    I reset t, time to 0 whenever it hits an object.

    Then ...

    onClipEvent (enterFrame) {
    t += .01
    vy += .5 * gravity * t
    }


    This seems to give me the right affect, especailly if I make gravity nice and low so I can observe the acceleration. The formula's not squaring t, but I think it works becasue vy is updated on every frame.

    Anyway, I thought I should run this by the math & physics departement! Does this make sense? And do you think other gravity affects are simulating acceleration due to gravity, or just a constant "downward" velocity?

  2. #2
    Senior Member Penleeki's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    223
    I usually use basically the same system you are using there vy+=gravity;
    I'm pretty sure its not an exact scientific model, but its close enough for me

  3. #3
    Senior Member pitchdog's Avatar
    Join Date
    Sep 2002
    Location
    Rochester, NY
    Posts
    128
    First, Bit oops! Wrong letter ... D = 1/2(gt^2). I've been plotting Distance (y) not vy. A is always the same.

    Further, I'm using vy+= gravity * t for my gravity simulation.

    Ok, now that that's cleared up ... you're using vy = g like this:

    onClipEvent (enterFrame) {
    vy+= gravity
    }

    For a moment I thought they were the same, becasue the frames should take care of the time part of the equation, but we're not multiplying by time!

    So, if g = 10, and on each frame if you just add gravity you get:

    Frame 1: vy = vy + 10, vy(1)= 10
    Frame 2: vy = vy + 10, vy(2)= 20
    Frame 3: vy = vy + 10, vy(3)= 30
    Frame 4: vy = vy + 10, vy(4)= 40

    but for vy+=g * t,

    Frame 1: t=1, vy = vy + 10 * t, vy(1) = 10
    Frame 2: t=2, vy = vy + 10 * t, vy(2) = 30
    Frame 3: t=3, vy = vy + 10 * t, vy(3) = 60
    Frame 4: t=4, vy = vy + 10 * t, vy(4) = 90

    Now that's acceleration!

  4. #4
    Senior Member pitchdog's Avatar
    Join Date
    Sep 2002
    Location
    Rochester, NY
    Posts
    128

    w/ respect to time.

    Ok then ... I think I've got it. There's clearly a differnce.

    http://home.twcny.rr.com/jpitcher/AofG.swf

  5. #5
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182

    :)

    The earths falling acceleration is 10 m/s2 (sqrt)...

    So the falling speed should first be 10, then 20, then 30 etc...

    But to move the char so much looks a bit unreal so we can use values of 1,2,3,4,5 etc...


    onClipEvent(load){
    falling = false;
    velY = 0;
    }
    onClipEvent(enterFrame){
    if(Key.isDown(Key.SPACE)){
    falling = true;
    }
    if(falling == true){
    _y += velY;
    velY ++;
    }
    }

    This code can easy be modefied to a jumping code... You'll then have something like this:

    onClipEvent(load){
    jumping = false;
    velY = -10;
    }
    onClipEvent(enterFrame){
    if(Key.isDown(Key.SPACE)){
    jumping = true;
    }
    if(jumping == true){
    _y += velY;
    velY ++;
    }
    }

  6. #6
    Senior Member pitchdog's Avatar
    Join Date
    Sep 2002
    Location
    Rochester, NY
    Posts
    128
    I should have had "y" instead of "vy" in my last post - that's I've been scritping graviy. We're interested in the postion, y at each interval.

    "So the falling speed should first be 10, then 20, then 30 etc..."

    Yes, the falling SPEED, vy, increases by 10, but I see a lot of programs where the position, not the speed, is increasing by 10. So, a ball would drop from 0, -10, -20, -30, -40 in five intervals but it should drop from 0, -10, -30, -60 -90. In short, it doesn't look right becasue velocity stays the same. I think people get away w/ it becasue for the first few seconds, the numbers are close enough, but most of the gravity balls look a bit odd to me.

    I think your script compensates for acceleration.

    Here's an example or two where I think I've accounted for the acceleration due to gravity.

    http://home.twcny.rr.com/jpitcher/gravitytube.html

    Here's the "Pitchdog" playing w/ the ball.
    http://home.twcny.rr.com/jpitcher/fetch.html

  7. #7
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182

    :)

    Yeah true,

    My code doesn't consider air fricition it's becuz it's jus' a simple code and for platform games it wont be realy needed to have gravity and stuff...
    I cant explain the effect of air friction myself very good, all I know is that if your on the moon (with no air friction) and drop a hamer and a feather at the same time/height, they drop at the same time/height...
    To realy see what I meen, I did a search on google and picked out some that seemed interesting...
    Good luck

    http://hyperphysics.phy-astr.gsu.edu/hbase/airfri.html
    http://www.thinkquest.org/library/li...ysics/air.html
    http://www.materialworlds.com/sims/T...orksheet1.html
    http://www.webeyedeas.co.uk/examples.../throwBall.htm (Flash source)
    http://cosmology.berkeley.edu/Educat...plemental.html
    http://www.ortphysicschem.com/cpoins...1/ch3vocab.doc (opens a .doc, wich contains some interesting links, the first movie is realy interesting)

    and so on.......

  8. #8
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Beyond the air friction thing, I would say something about the "real" gravity thing.

    There is no "real" gravity if we say "vy+=gravity*t;" by enterframe base. That is just "acceleration". Although it looks enough to animate a ball falling or throwing.

    By enterFrame base, we have assumed a constant speed. With that speed, the ball travels for a time of 1/FPS sec. If we plot the positions of the ball, the graph would be segments of straight lines. In real gravity, the speed is accelerated for each infinite small quantum of time. So, the speed is never homogenous during inter-frame period. The script "_y+=vy*t;" is based on homogenous velocity which is not true in real world.

    When the ball drops, what is the _y in the next frame ? OK, it is (1/2)*g*t^2; What is the vy in our script ? If we assume vy=0, the _y will be 0 in the next frame with speed being g*t. (weird ?). If we assume vy=g*t, then the _y will be g*t^t; It means the ball starts to fall with an initial speed of g*t not 0. Both answers are not correct. Because the velocity is changing from 0 to g*t during that period. The velocity is not homogenous.

    So, We could assume the speed to be just average of start speed and end speed ? Is that (1/2)*g*t ? No. It is wrong after the second frame.

    If we need "real gravity", we should calculate _y by (1/2)*g*t^2; However, it would be complex if we implement this in a game with ball bouncing up and down.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center