All I have to say about gravity is...how?
Ok a little more.
I need to add gravity to my game, I've looked at all the forum posts, code snippets, and whatever else there is out there. I've seen it. I even tried making my own gravity too no avail.
In the beginning my gravity code was:
if object position y(1)> 0 then move object down 1,4
Simple, it worked, move the object down as much as possible. But I knew it wouldnt last long because I knew I needed to add jumping and such in later on. Here's my second attempt at gravity, with jumping.
I made a checklist of what I wanted:
- Set gravity variable to 0
- If the user presses space
- set the gravity var to object 1's y + 100
- make the jump variable equal 1
- if the jump var is 1
- move the user up (move object up 1,4)
- if object 1's y equals the gravity var
- make the gravity and jump var 0 again
- move the user down
And ended up with:
GRAVITY#=0
JUMP#=0
DO
IF SPACEKEY()=1 AND JUMP#=0 THEN GRAVITY# = OBJECT POSITION Y(1) + 100: JUMP# = 1
IF JUMP# = 1 THEN MOVE OBJECT UP 1,4
IF OBJECT POSITION Y(1) = GRAVITY# THEN GRAVITY# = 0
IF OBJECT POSITION Y(1) > GRAVITY# THEN MOVE OBJECT DOWN 1,4
LOOP
That didnt work too well. So can someone please please please help me with possibly the worlds simplest gravity code ever.
All I need to accomplish is, if the user isn't on the ground (Im using objects as ground, not matrices) then move them downwards until theyre on the ground. When the space key is pressed, move them up a bit (like 100 units) and then have them fall again. While theyre jumping they cant keep jumping in order to get way up into the air. I dont need any velocity thing or complex angles to be determined. Just what I listed.
Even a tutorial someone could point out to me would help a lot. Or explain to me what to do in words and I could attempt to turn it into code. I just need gravity badly, and I cant find a good example of what I need anywhere.
Thank you all a lot.
- RUCCUS
Causin' RUCCUS whereva' I go.