Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Broseph Radson on October 01, 2010, 10:03:05 am

Title: Realistic gravity help
Post by: Broseph Radson 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.
Title: Re: Realistic gravity help
Post by: MRide 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.
Title: Re: Realistic gravity help
Post by: Runer112 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
Title: Re: Realistic gravity help
Post by: Raylin on October 01, 2010, 10:27:56 am
Wouldn't that make the sprite instantly fly up?
Title: Re: Realistic gravity help
Post by: Runer112 on October 01, 2010, 10:30:19 am
You mean my code? I tested it on my calculator and it appears to work fine.
Title: Re: Realistic gravity help
Post by: Broseph Radson on October 01, 2010, 10:49:05 am
Alright thanks! This worked pretty darn good :)
Title: Re: Realistic gravity help
Post by: DJ Omnimaga 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.