Search Unity

orbit script

Discussion in 'Scripting' started by xero21, Oct 1, 2009.

  1. xero21

    xero21

    Joined:
    Sep 29, 2009
    Posts:
    2
    Im having an issue with planetary orbits. Is there a universal script for objects orbiting other objects? I was thinking of probably copying the mouse orbit script. Is there an easier way to get the planets to orbit.
     
  2. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    Do you want realistic orbits controlled by physics, or just something to fake an orbit? If you want a simple faux orbit that's circular, just use Transform.RotateAround(). If you want realistic orbital behavior controlled by physics, I have a script for that (but it is at home, so I won't be able to send it until tonite).
     
  3. xero21

    xero21

    Joined:
    Sep 29, 2009
    Posts:
    2
    I will check out transform.rotatearound(). But in the end i will definitly want it to be an actual orbit around sun. So that script will defenitly be useful. Thank you very much. Also thanks to the forum because I was really stuck on how to approach orbits in a 3d enviornment.
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I made this:

    OrbitSim

    It's a physics based orbital motion simulator that uses actual data to simulate the motion of the inner planets (it could be applied to any number of bodies, I simply chose the inner solar system as an example). If that's the sort of thing you're after then let me know and I'll post the source project for you to digest.


    Note: the only thing not to actual scale in my simulation is the display size of each body (so you can actually see them). Otherwise all data, including masses, positions and velocities is based on actual data.
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I would like to see the source project for your orbiting program for learning purposes if possible.

    Thanks
     
  6. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    For Aubergine and anyone else that's interested:

    OrbitSim Source (1.9MB)

    Have fun!
     
  7. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    thanks for the code.

    However, it doesnt seem like to be working. All i see is a yellow spot(sun i guess) for a second and then disappears. Nothin happens then.

    And finally, the editor crashes.

    Is it because im using the trial or what?
     
  8. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Did you open my project as-is and run it, or did you make modifications? Are you on Mac or Windows? It needs to load the XML file locally and IIRC I only wrote it to find the file locally in a correct way on a Mac as that's what I'm using, you might need to tweak that part of the initialization code. Although saying you see a yellow spot indicates it has loaded at least one of the bodies meaning it's read the file.

    And please, why would it ever be a part of using a trial to have a crash? :p
     
  9. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Nice little demo project! :)
     
  10. golden_gate

    golden_gate

    Joined:
    Jul 22, 2009
    Posts:
    81
    Yes I would like to see this script too!


    :D
     
  11. Mutos

    Mutos

    Joined:
    Jan 12, 2010
    Posts:
    9
    Hi HiggyB HiggyB,


    Thanks for your sim. I just downloaded it. I'll reinstall Unity and gve it a try. I'll keep you informed.

    My goal falls somewhere in between using Transform.RotateAround and full physics sim. I just want to be able to simulate to exact scale a stellar system with only keplerian orbits.

    The issue I've found with most 3D packages lies with scale management. I want everything to be in its actual scale and the camera to just zoom and fly around objects.

    I'm nothing of a 3D guru, but not a complete n00b either. It's been long time I haven't coded, but I can get along with most languages.
     
  12. Afassolas

    Afassolas

    Joined:
    Apr 10, 2013
    Posts:
    78
    It did not work for me it gave lots of errors. I think it has compatibility problems with Unity 4.x
     
  13. apolzon

    apolzon

    Joined:
    Jan 8, 2014
    Posts:
    1
    I imported the uploaded zip into Unity 4, let it upgrade it, and fixed the error messages -- the ones that couldn't be automatically corrected were due to type inference errors when using the Array class, so I just switched those calls to use String[].

    Thanks for the script, haven't had a chance to dig through it, but should definitely be useful in guiding my development for my current project.

    I couldn't get the forum attachment system to work, so here's a link to the upgraded package: http://pastelink.me/dl/580dd9