Ok, I've been having problems with basic gravity lately... but I just now, without the help of any tutorials, made it work on my own. So here is the code, commented for anyone else with my problem.
And I will be working on collision next, so stay tuned!
EDIT: I meant conquered!
` Make our cubic friend.
make object cube 1,1
` Make a matrix for depth and movement perception
MAKE MATRIX 1, 100, 100, 100, 100
` Center the matrix where the cube starts
position matrix 1,-50,0,-50
` Set the initial y value for the cube, not really necessary, I just wanted
` to see it fall down at the beginning.
y# = 10
` Position the cube at its starting location.
position object 1,0,y#,0
` Set the sync rate.
sync on : sync rate 45
` Make a pretty and colorful box for absolutely no reason!
make object box 2,100,.1,100
color object 2,RGB(50,50,255)
` Make the box translucent! OOOOH!!!
ghost object on 2
` Color our cubic friend so he isn't ugly anymore
color object 1,RGB(255,0,0)
` Position our amazing box
position object 2,0,0,0
` Set the initial fall speed
fallspeed = .005
` Not quite sure what use this has in this program...
ay# = object angle y (1)
``MAIN LOOP``
do
`` Set up the camera to follow and point at
position camera 0,object position y(1)+2,-10
set camera to follow 0,x#,y#,Z#,ay#,5,3,1,1
` If the cube is in the air
if object position y (1) >= .5
` Make it FALL!!!!!
y# = y# - fallspeed#
fallspeed# = fallspeed# + .005
endif
` And this is for the jumping, this is so when the cube is not in the air
` it will still be affected by gravity, but make sure that when its not in
` the air, that there is no gravity to make it fall.
y# = y# - fallspeed#
` Movement... yeah yeah... Can only move if on ground though!
If object position y (1) <= .5
if rightkey() =1
x# = x# +.2
endif
if leftkey() =1
x# = x# -.2
endif
if upkey() =1
z# = z# + .2
endif
if downkey() =1
z#=z#-.2
endif
endif
` Ok, if the cube is on, or below (by some chance) the ground, make sure
` that he wont fall. ALSO!!! MAKE SURE YOU HAVE THE "and jump = 0" or else
` you will not be able to jump at all, because it will set the fallingspeed
` back to 0 the second you try to jump, so nothing will happen!
if y# <= .5 and jump = 0
fallspeed# = 0
endif
` If you hit the space key, and you are on the ground, set jump = 1, this is
` important because if you dont then you will just keep going up.
if spacekey() = 1 and y# <= .5
jump = 1
endif
` If jump = 1, then set jump to 0, so you wont keep going up (see!) and make
` the fall speed NEGATIVE so you will go UP^. What this does, is set the fall
` speed to negative 0.1, so that you will go up, but all the time, due to the
` earlier command that made sure the cube was always affected by fall speed, even
` if it was 0, the cube goes UP^!! And then, since the cube is in the air, the original
` gravity code starts to affext his ascent and eventually it counter acts it and makes
` him start going down again!
if jump = 1
jump = 0
fallspeed# = fallspeed# - .1
endif
` Update our little cubic friend's position, so its not like hes in a coma!
position object 1,x#,y#,z#
` Guess waht sync does! It syncs!!!
sync
loop
AMD Athlon 64 3200 - GeForce 6800 GT - 320GB Hard Drive
1024MB RAM