Code Snippets > Collisions and Physics ( Created 27 April 2007 | Last Edited 27 April 2007)

 Orbital Physics by shroom_monk | Rating 75%Continuous Freefall Written inBlitz Basically, it's a little red box using continuous freefall to orbit around a green circle. Like a planet and a sun. AppTitle "Orbit" Graphics 400,300,24,2 SetBuffer BackBuffer() Local sx# = 100,sy# = 150 Local sxv# = 0,syv# = Pi timer = CreateTimer(50) While Not KeyHit(1) WaitTimer(timer) sxv# = sxv# + (Cos#(ATan2#(sy# - 150,sx# - 200) + 180) * 0.1) syv# = syv# + (Sin#(ATan2#(sy# - 150,sx# - 200) + 180) * 0.1) sx# = sx# + sxv# sy# = sy# + syv# ;Cls Color 0,128,0 Oval 198,148,5,5,True Color 255,0,0 Oval sx# - 1,sy# - 1,3,3,True Flip Color 0,0,255 Oval sx# - 1,sy# - 1,3,3,True Wend FreeTimer timer End --> Uncomment the Cls to remove the trails. If anyone can find the perfect start point, gravity, or start speed, to make a perfect/near-perfect cirlce, then please let me know. Things you can change: Start position: Local sx# = 100,sy# = 150 --> Start velocity: Local sxv# = 0,syv# = Pi --> Gravity: sxv# = sxv# + (Cos#(ATan2#(sy# - 150,sx# - 200) + 180) * 0.01) syv# = syv# + (Sin#(ATan2#(sy# - 150,sx# - 200) + 180) * 0.01) --> ^Change the 0.01 to the gravity wanted. Must stay the same.^ |edit| Found an almost perfect orbit. Code updated. |edit| |edit| Found a better one. Interesting how Pi makes for a practically perfect cirlce... |edit|

Posted : Friday, 27 April 2007, 15:27
Jayenkai

Aww, man, I am gonna have SO much fun playing with this!!

Thanks
-->
WEEEEeeee!!!

Posted : Friday, 27 April 2007, 16:23
Blitz3Dman

It's an atom!!

-->

Posted : Friday, 27 April 2007, 17:13
magicman

Vote : 4
Thats pretty cool.

Posted : Friday, 27 April 2007, 17:17
Blitz3Dman

I'm making a really awesome one here, so hold on to your britches cause it's almost finished

Posted : Friday, 27 April 2007, 19:19
power mousey

ahhhhhhhh!!!

thanks shroom.

I'm beginning to see the light. Serious and True!

whoa!! and wow!!

over time and space...individual particles.photons
grouped in packets forming waves as part
of function in both time and space interacting
with other objects and relativities.
And in the grand expansion of the Cosmos relative
to the temporal locales. And as to the point of initial
singularity. True, I might point out. The singularity
point.

whoa I see, I see.

but there is also the z factor in our 3 dimensions...and perhaps beyond as well. Utilizing and using one dimension above. Its been theorized around at least 7 and up to 24 dimensions. But thats a different story and topic for
a later time.

thank you for sharing this program.

I have to ponder this.
And check this out. Think it thru.

good night,

Posted : Saturday, 28 April 2007, 00:02
shroom_monk

Posted : Saturday, 28 April 2007, 00:10
shroom_monk

Here's one for ya, with 3 planets!
-->

How long do you think it'll be before they crash?

And Jay, try making one, or even two, of your planets have a big gravity. The effects are interesting.

|edit| Like this: |edit|
-->

Posted : Saturday, 28 April 2007, 02:42

Vote : 4
I love the first one of those two...

Thanks, thats really nice!

Also, I love the second one, its weired!

Posted : Saturday, 28 April 2007, 02:50
shroom_monk

Well, of course, this is just a simple demo of the code. Feel free to take it, use it, and modify it how you want. Then post it here.

I think one thing I will add is a setting where the gravity has less affect as the object gets further away, like in real life.

Posted : Saturday, 28 April 2007, 03:03
shroom_monk

Now, gravity effect gets less, the further away the block gets. If the effect gets to 0, the you've lost it!
-->

Posted : Saturday, 28 April 2007, 06:37
Lineraf

That's pretty cool!

Here's a BlitzMax version:

-->

Posted : Saturday, 28 April 2007, 12:48
Blitz3Dman

Mwa ha ha!!!

A self-sustaning universe featuring planets, moons/asteroids/space debris, explosions, and gravity based on shroom's code!

Create planets by left mouseclicking!
Create moons/asteroids/debris by right mouseclicking!

-->

Posted : Saturday, 28 April 2007, 18:27
JL235

I made a few changes to it. But I think I might have broken it. I'm pretty certain the numbers I'm using are Shrooms original numbers, but the planet movement I get is different.

The changes I've made; added a Planet type and Planet functions (so it's easier to add more Planets), renamed 'sxv', 'sxy', 'sx' and 'sy', removed the timer and added delta time. But I don't understand why it's still not moving the way it was originally on Shrooms. Maybe me numbers are wrong, but I have discovered (by fluke) the perfect orbit.

-->

Posted : Sunday, 29 April 2007, 00:30
shroom_monk

@Blitz3DMan: Now that is good. Although, I think some of the collision detection needs checking, and it has a habit of crashing after a while (although I think that might just be my computer).

@DiablosDevil: Your program is effectively the same as mine - same orbit, etc... because you commented out the delta, so it doesn't have any effect. Still pretty good, though.

Has anyone found the perfect orbit for when gravity decreases as you move away (Orbit 3)?

Posted : Sunday, 29 April 2007, 06:09
Blitz3Dman

Although, I think some of the collision detection needs checking, and it has a habit of crashing after a while (although I think that might just be my computer).

Yea, I know and it's not just your computer. It happens a lot when you go crazy creating planets. And this code is a nice bit faster modifying only 2 lines of code
|edit| I fixed the collision detection. turns out I was detecting using the diameter instead of the radius. |edit|
|edit| I found out that I forgot to set gmul at minimum 0 so I was having some odd problems... |edit|
|edit| yet another edit: now planets use gmul and the collision still isn't fixed completely >.< |edit|
-->

Posted : Sunday, 29 April 2007, 10:32
JL235

Dam, I must have been comparing my code to someone elses. I swear last night I wasn't getting a perfect orbit with Shrooms code.

Posted : Sunday, 29 April 2007, 11:53
shroom_monk

Diablos: You get a perfect orbit with orbit 1 program only. My orbit's 2 and 3 don't have perfect orbit.

-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 648|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
 Latest PostsNoSex in England GfK Wed 15:22 Spinal's Search for Tech rockford Wed 14:45 Happy Birthday, Windows XP Jayenkai Wed 08:40 What Have You Done? - Oct 2016 GfK Wed 08:21 GoPro Hero 4 Silver vs Nikon KeyMission 170 Jayenkai Wed 01:51 Rhythm Heaven Megamix Kuron Wed 01:46 RIP - Bobby Vee Kuron Wed 01:36 El Stompo Jayenkai Tue 04:59 RIP - Pete Burns Jayenkai Mon 18:55 NerdBlock Jayenkai Mon 16:40 More

 Latest Items Blog : Spilling my Noodlessteve_ancell Mon 13:38 Link : Character generators! :DAfr0 Sun 07:58 Woot : Getting Noticed... for Gameboy Dev!Afr0 Sat 17:17 Dev-Diary : 1st Ever Wed Workshop Progresszzoom Thu 23:12 Showcase : Biomorph FractalsAndy_A Wed 12:43 Snippet : Fisheye Lens EffectJayenkai Wed 11:50 Snippet : 2D BallsJayenkai Wed 06:22 Showcase : Mining Map AI DemoStealth Tue 19:41 Showcase : Biotic Limit - Games For Better (2 Days) Editionrychan Mon 12:27 Dev-Diary : Intellivision Controller Adapterspinal Sun 11:33 Snippet : Contour Map from DataHoboBen Fri 18:14 Snippet : FPS Control (WASD+Mouse)Pakz Wed 22:30 Article : Concurrency in C#Afr0 Sun 12:28 News : Newsletter #281HoboBen Fri 04:18 News : Newsletter #280Jayenkai Sat 05:10More

Who's Online
zzoom
Thu, at 00:30
Jayenkai
Thu, at 00:27
spinal
Thu, at 00:00
rockford
Wed, at 23:32
Kuron
Wed, at 23:24
therevillsgames
Wed, at 18:54
Sammy
Wed, at 18:38