How to make things FALL and look REAL :)
Blitz3D Forums/Blitz3D Tutorials/How to make things FALL and look REAL :)
| ||
Hey I have seen many people ask how to make things fall like they do in real life. I can only assume they are tired of making things fall at a few pixels per second. Well here is a nifty trick that I discovered when I made my first platformer game and soon figured out I wasnt the only one that knew this. So here is how you do it step by step. 1. When you make a character or anything that will be affected by gravity give it a variable called velocity_y or vy.. whatever you want to call it Main loop 2. If the object hit the ground then velocity_y = 0 3. Add velocity_y to the y value. 4. velocity_y = velocity_y + gravity where gravity is a constant usually floating point variable. gravity should be positive in 2d and negative in 3d End of Main loop This works for 2d and 3d! to make an object jump set velocity_y to some bigish number in 3d it is positive, in 2d it is negative. simple example: Graphics 800,600,0,2 SetBuffer BackBuffer() ballx# = 200 bally# = 200 ball_velocity_y# = 0 gravity# = .1 bounce# = .5 While Not KeyDown(1) Cls ball_velocity_y# = ball_velocity_y# + gravity bally = bally + ball_velocity_y If bally# > 590 Then ball_velocity_y = -ball_velocity_y*bounce bally = 590 EndIf Oval ballx,bally,10,10 Flip Wend End this one even has bounce. set bounce to 0 to see it just stop like a normal character would. |
| ||
A better and more in-depth explanation/example at my BASIC Prog. Tut. in my sig: How to: Add gravity to your game and Simulate jumping |
| ||
You could also check out my youtube video explaining this method: http://www.youtube.com/watch?v=Gxuag5Y5IOc&list=PL8A42CAFEF785F0B6&index=5&feature=plpp_video |