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.

Code Snippets / ball physics + timer() synching

Author
Message
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 15th Jan 2004 10:07 Edited at: 15th Jan 2004 10:08
just a little demo I made last night.

it's basically 2D trajectory physics, synched up with the timer() to run at a constant speed regardless of framerate.

I think it's a relatively accurate system, which includes gravity (of course), and basic loss of energy on bouncing. the code is set up so that you can adjust the variables easily, and view the results. you can even add rudimentary wind if you want...

probably useful for anyone still struggling with gravity, and expecially usefull for those still using "sync rate 30" in their programs!

p.s. try changing the sync rate in this example, the system should run at the same speed regardless!

I've posted this in the codebase as well.

enjoy!

[edit] This was done in DBPro, no idea if it will work in DBC

Go Go Gadget DBPRO!
SteveK
20
Years of Service
User Offline
Joined: 24th Dec 2003
Location: US
Posted: 19th Jan 2004 22:57 Edited at: 19th Jan 2004 23:01
You Should make the gravity real. It could make it even better and stand out more.

That should work. If it doesn't then get acceleration to 9.81*time falling^2. I made it so whatever the initial velocity of the ball is ball bounce (the speed it bounces of the ground at) then whenever it hits the ground just reset the time.(I didn't read the code that well so im not sure it u already do.

I am the great cornholio. Take me to your TP!
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 20th Jan 2004 06:32 Edited at: 20th Jan 2004 06:59
yeah, the gravity currently doesn't have the ^2 part involved, but it would be really easy to add. I just adjusted the gravity constant until I got a simulation that lookd good to me.

as this is primarily for game development, I am generally more interested in making if "feel" or "look" right than being absolutely accurate.

that being said, I'll try what you said when I get home to my DBPro system tonight, and see if it looks better that way!

thanks for the input! I was afraid everyone was ignoring it

[edit] plus that code assumes that youre game world works with the scale 1 unit (pixel) = 1 meter. you would have to adjust the gravity constant based on your game world scale. [/edit]

Go Go Gadget DBPRO!
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 22nd Jan 2004 12:25
Command out of place at line 98

Anyone else?

All you need is zeal
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 22nd Jan 2004 18:39
are you using DBC?

i just tried the code again and it worked fine for me...

Go Go Gadget DBPRO!
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 23rd Jan 2004 04:20
No dbpro, latest patch. Nutty.

Hey can you take a look at my code? Im trying to sync a pendulum swing based on looptime#. Maybe you can figure out what im doing wrong.

http://darkbasic.thegamecreators.com/?m=forum_view&t=24316&b=1

All you need is zeal
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Jan 2004 10:37
Command out of place at line 181 ?

walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 28th Jan 2004 04:31
this snippet is in DBPro, coded in the BLUE IDE... haven't tried it with the original editor... works fine for me, don't know what I can say

Go Go Gadget DBPRO!
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 3rd Feb 2004 17:17
try this version... I think the comments were causing trouble. otherwise I have no friggin' idea!

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia Ti4200 AGP 8x 128MB
TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 17th Feb 2004 15:47
Works fine for me. Runs at about 390-425 FPS.

DBPro Update 5.2

Member of Tjald - Targeted Joint Addicted Liberation Diplomacy

I am (currently) 45% addicted to Counter-Strike. What about you?
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 19th Feb 2004 06:09
perhaps it's something to do with the DBPro version?

it doesn't use any 3D commands though.

anyway glad it works for you!

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
DracoFireDragon
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location:
Posted: 22nd Feb 2004 00:01
The time thing doesnt work because it seems timer() is entirely based on FPS, it doesnt run the same at Sync rate 30 and Sync rate 3.
Im thinking you should record Timer() over a course of time and use an average...:/

So im not so sure that the way you use Timer() to base events off of works correctly...
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 2nd Mar 2004 06:07
actually that has to do with the accuracy of the physics engine. basically running at only 3 fps will cause all sorts of problems, because the system needs a few more chances to update the trajectory of the ball.

All physics systems have similar problems, the realism breaks down below a certain point. This system becomes less and less accurate as the frame rate drops, but it's acceptable down to about 15 fps in my opinion.

if I was using more complex physics formulas, it would be accurate at even slower framerates, but this is for game programming, so 3fps isn't really worth worrying about.

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 2nd Mar 2004 19:22
hmz, when you shoot the ball at 90 degrees it does not bounce off once it hits the ground, even with a very large velocity. but nice job



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 3rd Mar 2004 08:21
hehehe, never even tried shooting the ball at exactly 90 degrees

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB

Login to post a reply

Server time is: 2024-05-11 06:19:00
Your offset time is: 2024-05-11 06:19:00