Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Avichal · Mar 31, 2011 at 02:05 PM · orbitplanet

Simple Planet orbit

Hi,

Can I get a simple script for movement of an planet in an orbit. I tried quite a few scripts, but as I am not an very gud programmer I had some trouble dealing with the errors.

Please provide me with an simple orbit script for a planet revolving around an Star.

Avichal Singh

Dsksupinfogame.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by e-bonneville · Mar 31, 2011 at 02:16 PM

I'm not sure why I'm writing a script for you, but just follow these steps:

  • Make an empty gameObject. Name it "CenterOfGravity" (or the equivalent in your language)
  • Make the planet(s) you want to rotate a child of the CenterOfGravity gameObject.
  • Copy the script at the bottom of this answer onto your CenterOfGravity gameObject.
  • For realistic behavior, move the CenterOfGravity gameObject to the position of your star.

JS script to put on your CenterOfGravity gameObject:

var rotationSpeed = 5;

function Update() { transform.Rotate(0,rotationSpeed * Time.deltaTime,0); }

Or in C#:

float rotationSpeed = 5.0f;

void Update() { transform.Rotate(0,rotationSpeed*Time.deltaTime,0); }

Please note that the above scripts are untested and may contain errors

Now, asking for a script and actually getting somebody to write it for you isn't very common and overall isn't a very good idea, so please try to avoid this kind of question in the future. Instead, a better way to do it might be to actually start trying to write the script yourself, and then asking somebody here if you have a problem with it.

Also, if this answer works for you, please accept it as correct. :)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Mar 31, 2011 at 03:31 PM 0
Share

You could put the script on the star ins$$anonymous$$d of an empty game object

avatar image e-bonneville · Mar 31, 2011 at 04:47 PM 0
Share

Yes, but then that would make the star rotate as well, and that might not be what the OP wants. It's just an unnecessary precaution on my part, I suppose.

avatar image Playerest · Oct 25, 2014 at 12:21 PM 0
Share

thanks, this was helpful.

avatar image futuremutant · Feb 21, 2015 at 05:11 PM 0
Share

mate this worked flawlessly, thanks for it!

avatar image
0

Answer by hellhoud · Sep 09, 2015 at 06:56 PM

@Avichal just use this javascript on any object (empty one works the best)

 function Update () {
     transform.Rotate(0, 1, 0, Space.World);
     }

then add the planet as the child

enjoy.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DaveA · Mar 31, 2011 at 03:37 PM

You could also just use the Animation editor to do what Elliot says. Make the planet a child (of the star or hidden object at the star) and animate that parent's rotation.

How simple is simple? If you want the planet to rotate as well as revolve around the planet, in a perfectly circular orbit, but its axis tilted (as most are), in addition to what Elliot has said, you'd want to have the planet rotate around itself too. But that's not enough, because the axis of rotation is constant relative to the universe, not just itself. Meaning if you did simply that, the planet's axis would always point away from the star. So you'd have to make the planet a child of yet another gameobject (empty or otherwise invisible), and that gameobject would counter-rotate at the same speed as the revolution around the star. Or maybe script it to set world-rotation (universe rotation in this case) at a constant axis. If you want orbits not on Y axis or elliptical, or based ephemeris, ping me directly.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Avichal · Apr 01, 2011 at 06:39 AM 0
Share

Well thanks ! Elliot and DaveA ! And yes asking for a script is not a good idea :P but thanks for the script and it worked wid animation too :D Thanks a ton !

Avichal Singh Dsksupinfogame.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Axial tilt and moons 1 Answer

Itween for curved orbital movement? 1 Answer

Simulating 2D planetary gravity and trajectpry using Unity 0 Answers

How to rotate a player when using Mario Galaxy style gravity? 5 Answers

draw planet orbit on solar system 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges