Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RetnuhStudio · Mar 26, 2018 at 11:57 PM · rotationrotate objecttime.deltatimerotatearoundtime.time

Rotate object based on set time.

I'll try describe this as best I can.

I have a galaxy map in a space tech demo I'm working on. Currently I'm rotating the planets around in their systems by calculating an ellipse then rotating the object along that ellipse using a progress from 0.0f - 1.0f like so.

 float orbitSpeed = 1f / orbitPeriod;
 orbitProgress += orbitSpeed * Time.deltaTime;
 orbitProgress %= 1f;
 if (orbitEllipse != null) orbitPosition = orbitEllipse.Evaluate(orbitProgress);

However if I am to disable that planet when it is off screen then re enable it some time later when it is back on screen then its position will still be where it was when it was disabled.

What I want to achieve is have the planet be at the position it would if it was not disabled. I guess I'm trying to calculate its position based on a set time since the start of the game. Maybe Time.time? Dunno if I've explained this clear enough. Let me know.

Regards - Matt

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

2 Replies

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

Answer by RetnuhStudio · Apr 03, 2018 at 08:53 PM

Must have been having a mind blank hahah. Turned out it was as simple as changing this line here

  float orbitSpeed = 1f / orbitPeriod;
  orbitProgress += orbitSpeed * Time.deltaTime;

to

 orbitProgress = (Time.time / orbitPeriod);

or

 orbitProgress = (scriptGlobalManager.instance.tick / orbitPeriod);

I chose the second one as I wanted a independent tick rate I can control in the tech demo. It's just a float incremented by 1 every second. Like this.

 tick += Time.deltatime.
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
1

Answer by remy_rm · Mar 27, 2018 at 07:26 AM

there are multiple ways you could go about this, when you disable the gameobject of your planet it will also stop all logic in the scripts on it, thus leaving it at the place of deactivation.

What you could do is make a single gameobject containing a script that manages all plantes (ofcourse this is not feasable if you got ALOT of planets) , this gameobject would always be active and keeping track of the position of all your planets. then when you disable the planet the logic behinds it rotation keeps running in the manager. then when you enable the object againt it will grab its location/rotation from the manager script and directly snap to there.

If you got a lot of planets and a manager isn't feasible you could do this with a parent/child system where the logic for its position/rotation is in the parent, (just an empty game object with the script attatched) and you just disable the child object that contains the model for the planet and everything else regaridng the planet. Though not as optimal As the parent will still keep moving constantly it still saves the haulage of having to render your planet.

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 RetnuhStudio · Mar 27, 2018 at 07:15 PM 0
Share

Thanks for the answer. Currently I'm using object pooling to render the planets when they are on screen so I think mesh / render wise I'm about as efficient as I can get there. All the planets / moons rotations are currently handled on one script that is on the systems base (currently the host star).

 foreach (scriptCelestialBody b in celestialBodies)
         {
             Vector2 pos = new Vector2(system.position.x, system.position.y);
 
             if (b.orbitObject == null)
                 b.position = pos + b.orbit.AnimateOrbit();
             else
                 b.position = b.orbitObject.position + b.orbit.AnimateOrbit();
         }

There are about 1000 systems and around 3000 planets currently and this code here is currently at 8.4ms in the profiler.

One thing I was thinking of was maybe updating orbits that are off screen every x number of frames and just increasing their orbit speed to make up for the frames skipped?

Anyone have any other ideas?

Thanks

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

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

rotate object around another object 1:1 1 Answer

Rotation Problem - Simulating Gimbal lock 1 Answer

Rotate object in the direction where it is going 1 Answer

90 degree rotation script, cant find or make one that works for my needs. 1 Answer

How to Rotate Object around point only 90 Degree. 1 Answer


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