Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Look, its a bird, its a plane, no, its....Gravity :(

Author
Message
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Feb 2005 05:37
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:

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:

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.
Teh Go0rfmeister
21
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 28th Feb 2005 05:52
imnstead of having gravity a variable, have th emass of the objects a variable. have an array with all the objects and their masses, and have them fall accelerating at 9.8m/s^2 until they hit an object. for realism you could also have the Gforce required to make them break, and if they hit at that force then the object breaks

then for jump have the mass go negative in a parabola so it decelerates and then returns to a positive speed with acceleration.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Feb 2005 06:12
Elgoorf, I dont think that's what Im looking for. And like you said in IRC you didnt read what I posted so I guess you didnt know what I was looking for. Just some things...
What are you doing with the mass, all you mentioned was to give all the objects a mass, then that was it. Nowhere does the mass come into play with the falling...I think. Maybe that's because I haven't looked into arrays yet...
I'll try comming up with something along the lines of what you said but I'm still open to some other option that's simpler than that.

Causin' RUCCUS whereva' I go.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 28th Feb 2005 08:33 Edited at: 28th Feb 2005 08:34
This is the basics of gravity code, well corrected by robocat at the end aswell...is that any help ?
http://forum.thegamecreators.com/?m=forum_view&t=49419&b=7
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Feb 2005 09:37
Looking now o.O

Causin' RUCCUS whereva' I go.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Feb 2005 09:39
Lol that was the main one I was looking at, It makes sense but I dunno it didnt work with mine. I think I got an error when I tried implementing it, there was some line in there that didnt look right to me and I was right it was something like Object position. Look at it again and see if there is indeed an error in there. I want that to work so much but I couldnt understand it enough to fix the error.

Causin' RUCCUS whereva' I go.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Feb 2005 09:40
P.S: I think that code works only for matrices, no?

Causin' RUCCUS whereva' I go.
Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 28th Feb 2005 12:31
yah there is one little parameter missing in the last bit of code. I have fixed it here



The code will work with any ground. you just need to assign the variable ground_height to be the top of the object you are using for ground. I added jump using spacebar. It should work though I have not tried to compile it

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 1st Mar 2005 07:01
GREAT! I'm not sure it works yet but from what you've said it probably will. Ill try pluggin her in to my prog a lil later on, got homework right now. Thanks a bunch even if it doesnt work (probably will end up bein my fault if it doesnt )

Causin' RUCCUS whereva' I go.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 1st Mar 2005 07:45
No problem..and thanks coding fodder for the corrections...ill go change the post now !

Login to post a reply

Server time is: 2024-11-27 23:35:21
Your offset time is: 2024-11-27 23:35:21