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.

Author
Message
Jbolts1
19
Years of Service
User Offline
Joined: 1st Jan 2005
Location:
Posted: 26th Feb 2005 13:27
I need help serring up a gravity code and making it work.
Can some one plz help me.

Jbolt
Nic
19
Years of Service
User Offline
Joined: 26th Jun 2004
Location:
Posted: 26th Feb 2005 13:57
got a messenger Address? Im kinda a newb but it think i can help.
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 26th Feb 2005 19:38
do you need collision as well, if so what is he landing on (matrix, terrain, object ?)

`The basics of gravity code is you have a variable to store the strength of gravity.
Gravity#=-9.8

`You also store Vertical speed in a variable, this is how fast you rae moving up of down.
VertSpeed#=0



`ok so now we get to the main part, in the area where you handle the character code you add the gravity to your vertical speed.
VertSpeed#=(VertSpeed#+Gravity#)

`And then reposition your character (num is the num of the object you are using as your character)`
x#=Object position x(num)
y#=Object position y(num)
z#=Object position z(num)
Position object num, x#, (y#+VertSpeed#), z#


` And thats it really, of course youll need some kind of system so your player doesnt fall through the floor, for matrices it would be like this
if object position Y(num)<Get ground height(1,Object position x(num),Object position z(num))
position object num,object position x(num),Get ground height(1,Object position ,object position z(num)
VertSpeed#=0
endif


`Also with this code its really easy to implement jumping, if they press the key to just just say
VertSpeed#=10
`or some other value, your choice, the larger the number the higher he jumps, also if the falling is too fast just lower the value of Gravity#

Hope that helps!
robo cat
20
Years of Service
User Offline
Joined: 23rd Feb 2004
Location: In a cat litter tray, near you...
Posted: 26th Feb 2005 21:01
Thats the way to do it, but it'll be faster to put 'get ground height' into a variable, rather than recalculating it each time

ground_height# = Get ground height(1,Object position x(num),Object position z(num))
if object position Y(num)<ground_height#
position object num,object position x(num),ground_height#
VertSpeed#=0
endif

Simple... yet fun!
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 1st Mar 2005 08:07
A little update on the code by 'Coding Fodder'
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 2nd Mar 2005 05:05
Baggers, just one other question.

After tweeking the code a bit I got it working and the guy jumps nicely, except its SO fast! He jumps up and down in 1 second. Could you please tell me how I would go about slowing this down?

Unless...Is this code just POSITIONING the user way up high rather than moving them there? If so could you tell me how to make it so instead of positioning them higher it would actually move them. Ill keep experimenting if I happen to get it but could you or someone else give me a hand?

Causin' RUCCUS whereva' I go.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 2nd Mar 2005 05:09
Ack, I think I found the problem. I think its in the line:

Im still trying to figure out how to make this work but I'm not sure. Using move object up wont work because there's too many parameters...Any ideas?

Causin' RUCCUS whereva' I go.
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Mar 2005 06:37
The added code is designed to change the object's speed do regardless of the fps the speed it moves is still the same.
Think of it like this...all the calculations we use were designed for use once a second (e.g. gravity is 9.8 meters per second) however the computer is running at over 100 fps and so it is effectivly running at over '100 seconds' per second...sorry it is a weird concept but the computer is doing everything right, just way too fast, so by dividing values by the screenrate we bring them back to the correct speed.
I still also recommend using a 'sync rate' command at the begining of your code aswell, around 60 is a good value, it just stops the program from fluctuating too much.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 2nd Mar 2005 06:38
Yay! Lol I scrapped the version I was using from you guys and came up with my own. I don't know how good it is but basically it will:
- Apply gravity to you if you're not on ground level
- Allow you to jump, but not jump WHILE you're jumping (to prevent cheeting )
- Let you see that you're actually moving.

Im going to post it on the code base forum and Ill add it to the code base, in version 2 Ill be adding:
- Smart gravity that allows you to fall until you hit an object,
not until you hit ground level.
- A decrease of speed as you go up when jumping, and an increase of speed as you fall for realism.
- Fall damage
- Having things break if they fall from a high enough distance, as recommended by....someone, I forget who Sorry to whoever did.

I know your system is very good and did all of this and most likely with less lag but this way makes more sense to me and I think it'll make more sense to the noobs. Well, look for the code in the code entry forum / the code base.

Causin' RUCCUS whereva' I go.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 2nd Mar 2005 06:39
Oh, lol now you reply when I come up with something else. Oh well I think I'm going to stick with my way for now, thanks for the help though your system helped me design mine.

Causin' RUCCUS whereva' I go.
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Mar 2005 07:24
No sounds good, well done at doing your own way, as long as it looks and plays good it doesnt matter !
Baggers
Jbolts1
19
Years of Service
User Offline
Joined: 1st Jan 2005
Location:
Posted: 11th Mar 2005 04:41
in stead of having to write gravity i got nuclar glory so it does it for you

Jbolt
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 11th Mar 2005 05:57
Not everyone wants to use that style of collision, i like to customise my stuff more, plus i like the challenge!
White Devil
19
Years of Service
User Offline
Joined: 21st May 2004
Location: Just where ur imagination cant go
Posted: 9th Jun 2005 03:52
Hello i'm kind of newbie too, and that code is great! i love it, and i tryied to apply it to an object but have a bug :S i stay like "jumping" every time (sorry for my bad english) here's the code ... any idea please???



any idea please?

Thank you

"I'm you, you're me, he's she.. oh god"
P4 2.26 Ghz, 256 kb Cache, 512 DDR PC2100, 80 Gb HD, ASROCK MoBo, Asus GeFORCE FX5200 v9520 128 mb, WinXP Pro SP2
White Devil
19
Years of Service
User Offline
Joined: 21st May 2004
Location: Just where ur imagination cant go
Posted: 9th Jun 2005 07:31
well it didnt work, and i have NGC DLL i can use that gravity, but it look very fake, or am i doing something wrong? i mean i have a gravity value of 10 and look very faked it doesnt look real.

Any tip then? or what about the code i posted???


Thank you

"I'm you, you're me, he's she.. oh god"
P4 2.26 Ghz, 256 kb Cache, 1.00 Gb DDR PC2100, 80 Gb HD, ASROCK MoBo, Asus GeFORCE FX5200 v9520 128 mb, WinXP Pro SP2
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 9th Jun 2005 16:13
Well im just about to leave for college but when i get home tonight I'll definately see whats up,
Funny though, I thought this was someone asking the same old questions about collision and id have to link them to this thread again !

qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 12th Jun 2005 07:49 Edited at: 12th Jun 2005 07:50
here's my gravity code if anyone wants it


in real life you accelerate as you fall (your downward velocity, which i call fall#, increases) and then you reach a maximum velocity when wind friction cancels gravity's acceleration out

at the top of my code i have:


0.02767 units per loop per loop is about 1.66 units per loop per second which is about 98 units per second per second (at sync rate 60) which is 9.8 meters per second since each DB unit in my game is one tenth of a meter. however when i use real numbers everything seems slow so i added .02 to the acceleration

so you need to do, somewhere in your code, cy#=cy#-fall#

@white devil nuclear glory's gravity looks fake because it's a constant speed

Check out the DB Freebie Archive: http://lysergium.net/dbfree/ thanks to DARKGuy
master programmer
18
Years of Service
User Offline
Joined: 30th May 2005
Location: 3D Space
Posted: 14th Jun 2005 06:49
Go 2 google and look for gravity codes. If not...I'm sorry, I'm still trying to figure it out also.

______________________________________
<<<<I can program using anything>>>>
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Jun 2005 07:31 Edited at: 14th Jun 2005 07:33
Just follow this link to RiiDii's mostly useful functions. I have an independant function that you just plug in the object number and the acceleration, and you have gravity. And in only two lines of code. No need for you to keep track of anything; no variables or arrays - it takes care of it all. It's also timer-based movement so regardless of the fps, it will always be smooth and nearly accurate.

http://forum.thegamecreators.com/?m=forum_view&t=55484&b=11

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 14th Jun 2005 07:44
Um 'master programmer' what the hell are you on about ?....there is a huge amount of info in this post with 2 or 3 solutions to the collision problem.

NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 14th Jun 2005 22:46
Jbolts1,

Note that 9.8m/sec squared, stands for the amount of added acceleration each second, of an object towards the earth. To clarify, if an object is initially at a stand-still, once dropped, the first second of fall the object would have fallen aproximately 9.8 meters. The second, he would have fallen 29.4 meters.

Acceleration means that the rate is increasing, even as decceleration means that the rate is decreasing. As you should see above, at the second second of fall, the rate of acceleration has increased, and the distance fallen had doubled that of the distance fallen at the first second. So, each second the rate of fall is increased by one exponent. To assure you understand, then at three seconds the fall distance would be 58.8 meters, and the rate of fall would be 29.4m/sec.

So, we see that the rate of fall changes, and does not simply stay at a rate of 9.8m/sec every second of the fall.

Below is a code snippet of a cannonball shoot. It uses three main values. One, which is the vector(speed and direction) of the cannonball made by the cannon, which stays constant until the ball comes to rest. And, two, which is the rate of fall downwards towards the ground. So, as the cannonball travels is constant path with a constant speed, as the acceleration of gravity on the ball is increasing. So, there are two forces acting upon the ball;cannon force and gravity.

In the program, first a new position of the ball, using the constant vector of the ball, is calculated. Then, using those new values, a newer position of the ball is calculated by adding the current distance of fall to the values last created. This program follows the laws of physics, closely. It also is fully executable. Just copy and paste the code into your editor and run it.




+NanoBrain+
poisoned
18
Years of Service
User Offline
Joined: 6th Jun 2005
Location: the shadow realm
Posted: 17th Jun 2005 12:56
i tried to mod baggers code to work with bsp collision but, and make it so you don't slide down ramps but it didn't work. I'm starting to think its not possible



Intel P4 3.6Ghz
1G PC3200 DDR

Login to post a reply

Server time is: 2024-04-18 16:31:23
Your offset time is: 2024-04-18 16:31:23