orbit script

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.

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).

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.

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.

I would like to see the source project for your orbiting program for learning purposes if possible.

Thanks

For Aubergine and anyone else that’s interested:

OrbitSim Source (1.9MB)

Have fun!

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?

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? :stuck_out_tongue:

Nice little demo project! :slight_smile:

Yes I would like to see this script too!

:smile:

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.

It did not work for me it gave lots of errors. I think it has compatibility problems with Unity 4.x

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