Author Topic: Realistic gravity help  (Read 3542 times)

0 Members and 1 Guest are viewing this topic.

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Realistic gravity help
« on: October 01, 2010, 10:03:05 am »
Well, yesterday i was attempting to make a program in Axe that used realistic gravity (like in Portal and Mario) to make a box jump around on command. Unfortunately, i somehow forgot my gravity formula that i'd used in an earlier program in BASIC that did the same thing, and i've since had so many ram clears (lol) that i've lost that program :'( .

I must be retarded or something because its very simple, but i tried for hours yesterday to remember the formula for realistic jumping gravity, and ended up listening to my ipod and not paying attention in class. I have very bad ADD, and i blame that for my inability to figure anything out lol.

So yeah, i need some help figuring this out.

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Realistic gravity help
« Reply #1 on: October 01, 2010, 10:10:38 am »
Well, acceleration due to gravity is -9.8 m/s/s, but jumping is whole 'nother matter.  Builderboy's pretty good at this stuff, you might want to ask him.  Here's what I know:
1) You need an initial velocity when you jump.
2) Gravity is constant negative acceleration.  (Which means everything is always accelerating down)
3) Your horizontal velocity doesn't change for a projectile (although if you're jumping, disregard horizontal velocity)
4) Your velocity coming back down should equal the opposite of your velocity going up.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Realistic gravity help
« Reply #2 on: October 01, 2010, 10:14:56 am »
Make a loop that constantly adds a velocity variable to the y-position variable, and if the object is not at rest, subtracts some value from the velocity variable every iteration. To jump, set the velocity variable to a positive value.

A basic example (also attached):
Code: [Select]
.GRAVTEST
ClrDraw
[FF818181818181FF]→Pic1
56→Y
0→V
Repeat getKey(15)
!If Y-56
0→V
If getKey(54)
7→V
End
Else
V-1→V
End
Pt-Change(44,Y-V→Y,Pic1)
DispGraph
Pt-Change(44,Y,Pic1)
Pause 32
End
        Pseudocode:
Code: [Select]
Header
Clear screen
Object sprite
Initialize y position
Initialize y velocity
Until user presses clear
  If object is at rest (bottom of screen)
    Set velocity to zero
    If user presses 2nd (jump)
      Set velocity to a positive value
    End
  Else, object is not at rest
    Decrease velocity
  End
  Update y position and draw sprite
  Update screen
  Clear sprite
  Delay
End
« Last Edit: October 01, 2010, 10:38:12 am by Runer112 »

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
Re: Realistic gravity help
« Reply #3 on: October 01, 2010, 10:27:56 am »
Wouldn't that make the sprite instantly fly up?
Bug me about my book.

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm







Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Realistic gravity help
« Reply #4 on: October 01, 2010, 10:30:19 am »
You mean my code? I tested it on my calculator and it appears to work fine.

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Realistic gravity help
« Reply #5 on: October 01, 2010, 10:49:05 am »
Alright thanks! This worked pretty darn good :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Realistic gravity help
« Reply #6 on: October 01, 2010, 05:01:38 pm »
One thing I have troubles with with gravity is checking if I am touching a wall or the ground, but making sure I won't slightly go through it or end up bouncing a few pixels before reaching it. In Super Sonic Ball you could notice that issue in screenshots, although that game was meant to be simple and as fast as possible, so I did not mind much.