Search Unity

Planetary Gravity

Discussion in 'Made With Unity' started by CoatlGames, May 13, 2009.

  1. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    hi there

    i was playing with unity's physics and i was trying to set up gravity on a sphere, to make some kind of planetary gravity in which things would "fall" to the sphere, and if they are going to fast orbit it..

    this is what i have so far:

    http://www.coatlstudios.com/planetarygravity/planetarygravity.html


    go there if you have some spare minutes to spend looking at it 8)
     
  2. SerKevin

    SerKevin

    Joined:
    Apr 13, 2006
    Posts:
    24
    Neat effect, looks like you are well on your way.
     
  3. Train

    Train

    Joined:
    Apr 22, 2008
    Posts:
    344
    Yes, this effect is nice.
     
  4. aaron-parr

    aaron-parr

    Joined:
    Apr 22, 2007
    Posts:
    577
    I like how the cubes and balls are affected by moving the camera... as if you were really spinning the objects.

    Nice effect over all. You should play with the concept of escape velocity.
     
  5. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    the cubes and balls are not affected by moving the camera, the camera just orbits the big ball... the cubes and balls are actually spinning around the big ball as matter of gravitational consequence of the big ball fast spinning, note how the cubes and balls end making a ring around the big ball equator due to the rotational forces 8)
     
  6. aaron-parr

    aaron-parr

    Joined:
    Apr 22, 2007
    Posts:
    577
    Are you sure the cubes are not affected by moving the camera?

    I violently twisted the earth around and noticed the cubes, and balls changed their trajectory, some moving away from the "planet", others bunching up in odd ways, all in sync with the movements I had been throwing at them.

    Perhaps I am imagining it, but it looks like that to me.
     
  7. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Neat. I have to get off my butt and touch-up/post my gravity simulator (simulates our solar system in Unity). It's of the same ilk but on a slightly larger scale with many many bodies.

    Kudos!
     
  8. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Need.
     
  9. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Ok, by end of week it'll be on my work blog. I promise. If I fail you can, well, I dunno, talk trash about me? :)

    But back on topic, what's the impetus for your work dodongoxp? Is this just experimentation or are you working on some cool game that needs this sort of thing?
     
  10. Sandor

    Sandor

    Joined:
    Apr 17, 2009
    Posts:
    91
  11. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    im experimenting because i want to try an idea of a game which deals with this kinda of stuff, planetary and cosmic stuff and manipulate gravity and forces and make a mess with planets and stuff hehehehe

    Nope.. i wrote my own gravity scripts 8)
     
  12. CosmoKing

    CosmoKing

    Joined:
    Feb 23, 2009
    Posts:
    111
    podperson made some "faux gravity" scripts a while back. I only tried it with a wheeled vehicle and it went into orbit when I drove too fast .

    Can't seem to find the thread though. :?
     
  13. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732

    :whistle innocently:
     
  14. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Today, today, I must do it today...

    (simple GUI added, just completing the full solar system instead of only the inner four)
     
  15. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Yeah, podperson did some of those. I think I still have the ones he worked over for me. Once I get home I'll post them.
     
  16. WillBellJr

    WillBellJr

    Joined:
    Apr 10, 2009
    Posts:
    394
    Appears that the link is down?
    When I first clicked it, it crash IExplorer (all open instances of it too!) - Now I just get a 404??

    Yes, planetary gravity will be a major part in my game - I haven't figga'd out how I'm going to implement it yet - I would have liked to have seen this...

    -Will
     
  17. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
    I tried looking at it over an hour ago and i got a 404 :?
     
  18. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    We did have a brief outage (like 10 minutes long) earlier today, that may have been during that window.
     
  19. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
    I meant that the url posted by the OP leads me to a 404. I haven't had a problem with the forums.
     
  20. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    hi there, im sorry.

    i removed the example, i thought the thread was old enough and wasnt going to get more replies and removed it
    sorry :oops:
     
  21. WillBellJr

    WillBellJr

    Joined:
    Apr 10, 2009
    Posts:
    394
    How is the thread old when it started on the 12th?

    -Will
     
  22. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Yeah.


    Just a word of advice, don't ever remove anything from the Unity forum that someone might find really useful. Its really annoying to come across an older thread, and find that all the images are gone, and the link doesn't work.
     
  23. TheRedTape

    TheRedTape

    Joined:
    Apr 13, 2009
    Posts:
    73
    Hej!

    It sounds very interesting anyway.
    Any chance that you will be re-uploading it again? :wink:
     
  24. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Hey all, I've finally posted a demo of my project in its current state. It's not 100% done and so I'm not yet sharing the source but I thought I'd let folks take a peek anyway:

    OrbitSim


    In order to make this work I had to tinker with the scale of things, so 1 world unit is actually an AU (the average distance of the Earth from the Sun, or 1.49598 x 10^11 meters), one unit of mass is an Earth mass (5.9742 x 10^24 kg) and each second the simulation runs is actually a full Earth day (8.64 x 10^5 s). But everything in my simulation is accurate to scale except the size of each body as each of those are magnified immensely so they'll show up and be more than pixel (or sub-pixel) dots moving around. :)

    The only thing driving motion in this simulation is the calculated and applied (via PhysX) forces of mutual gravitational attraction.


    To explain the numbers along the bottom:

    TE: this is the total energy of the system, it's calculated each step of the simulation and is the sum of the potential energy between each pair of bodies and the kinetic energy of each body individually. For a system to be "closed" (the bodies stay in a system like our solar system does) the total energy must be less than zero. A total energy of zero or above is an "open" system and the bodies won't be bound in orbit in any way, they'll just fly off to infinity (this is how you calculate a rocket's escape velocity, how much kinetic energy is needed to make the rocket/Earth system's total energy greater than zero). You'll see a number in parenthesis next to the total energy, this is the percent change since the simulation started (so I trap the total energy at the start, then calculate it again each step and compare those). A perfect simulation would have _zero_ change as energy should be conserved. My demo is reasonably good but far from perfect.


    Time: this is the total time elapsed since the simulation began and it's listed in Earth years. Keep in mind that each second of the simulation is one Earth day, and I have Time.timeScale bumped to 50.0 to keep things moving quickly (solar system time scales are HUGE).


    FPS: duh. :)
     
  25. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    'Sup,

    Higgy, I can see no content at all in any of the 4 frames, is it what it's supposed to be ? Do I have to wait or something to generate ?
     
  26. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Nope, should load quickly (the app loads and pulls an external XML file with the orbital system data, but it's like a few kb of text, that's it.

    What do you see along the bottom? Are there numbers for the total energy (TE) or NAN or ???
     
  27. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    yep numbers.

    edit : TE = a static 0, 00000000%, Time = (progressive data), FPS = .. 62 haha :D
     
  28. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Hmph, that's a sign that there are zero bodies in the system then as there should be a non-zero total energy for sure.

    Please PM me your config info (OS, browser, player version) if you don't mind. Thanks!