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 nikkouskouk · Oct 13, 2015 at 11:51 AM · 2d-physicseulerangles2d rotation

Recreating scene objects at next level

Hello i have a simple 2d scene with a block that rotates arround self over time.Whenever the player press the mouse click i instantiate another block make it child of the first block save the euler angles of the parent and move the child 2 units away from the parent so the child rotates arround parent.I do this some more times and then i move to the next scene.All the child objects have colliders and if they collide i destroy them.On the next scene i have a script that loads the euler angles that the player clicked and while the parent block rotates with the same speed i want to recreate the objects exactly at the same way.The script that rotates the parent is this.

   float[] floats;                            //the actual ange.z floats stored in the first scene
   angle = transform.eulerAngles ;
    void Update() {
     angle.z += Time.deltaTime * 80;
     if (angle.z >= 360)
     {
         round++;                   //fire each child every round (every one full rotation)
         attackedThisRound = false;
         angle.z = 0;
     }
     transform.eulerAngles = angle;
     if (round < floats.Length && !attackedThisRound && angle.z >= floats[round] )
     {
         InstantiateChild();
         attackedThisRound = true;
         Debug.Log("Desired :" + floats[round] + " Actual:" + transform.eulerAngles.z);
     }
  }

Now What is happening.Lets say i fire a block when the Parent's ange.z is at 45.565f. At the next level it will be fired between 44.5-47.5f and the child may land on another child and destroyed.Now this when tested in different pcs with different frame rates will have a lot worse results,on mobile even worse. These are some logs from the unity editor.Testing on my devices i had ~5f max error. Desired :209.7344 Actual:209.5964 Desired :253.9744 Actual:254.9251 Desired :291.1291 Actual:291.6958 Desired :326.7104 Actual:326.6832 Desired :1.343259 Actual:1.261122 Desired :142.5259 Actual:143.0578 Any ideas?

Comment
Add comment · Show 2
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 nikkouskouk · Oct 13, 2015 at 11:21 PM 0
Share

I tried setting the physics time.fixedTime to 0.01 and move above code to fixed update so every FixedUpdate i rotate the cube by 0.8. and then i check if angle.z >= floats[round]-0.4f so the max error will be 0.4 degrees. Am i right?Will the 0.01 fixed time step affect my game performance?Is there any other way that i m missing?

avatar image nikkouskouk · Oct 14, 2015 at 09:00 AM 0
Share

I am so confused. Setting fixed time step to 0.01 had a lot better result in unity editor,almost acceptable and 1800 fps. But building and exporting to my android device(lg g3) there was a constant lag all over the scene.I use only 1 parent , 10 child sprites and one script.Nothing more. Edit: It seems like Android devices have Vsync enabled.When i enabled it at Quality settings ,editor had lag too!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DiegoSLTS · Oct 14, 2015 at 02:26 PM

I'm not sure why you're changing the scene if you want things to keep moving, it's like you're setting up a hard problem to solve that could be avoided.

Anyway, you're doing physic stuff in the Update function, that's why you get different results with different framerates. Use FixedUpdate instead. But note that Unity's physic simulation is NOT deterministic, it's not ensured that the same objects in the same setup will move always the same way. Ofcourse they follow the same laws, but a lot of things can alter the result.

Also, have you tried setting anything you want to keep from one scene as DontDestroyOnLoad? Unity will keep those objects in the scene when loading a new one, but I'm not sure how the current physic state is handled (I guess it's not altered, but physics are complicated, and loading a new scene messes with time and framerate for a few milliseconds).

Comment
Add comment · Show 3 · 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 nikkouskouk · Oct 14, 2015 at 03:26 PM 0
Share

Ok you are right thanks. As i mentioned above i am using FixedUpdate ins$$anonymous$$d of update now and i think its working ok now. I forgot to change Deltatime to FixedDeltatime and the results were messed up. Anyway still i dont understand why the game lags in my android device.I used an FpsDisplay script and the game has always 60 fps but the image is jerky/choppy when the objects rotate.I ve tested in bluestacks and jennymotion and they still lag at constant 60 fps.

avatar image DiegoSLTS nikkouskouk · Oct 14, 2015 at 06:29 PM 0
Share

I don't know about that, maybe your FpsDisplay script is not working O$$anonymous$$? $$anonymous$$aybe you should ask a new question for that, it doesn't sound related to this question.

avatar image nikkouskouk DiegoSLTS · Oct 14, 2015 at 11:08 PM 0
Share

This is the script i am using link text . Well maybe you are right i should start a different question regarding the frame rate.Thanks for your time!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make a 2d object back flip when a key is pressed 0 Answers

RotateAround using physics 1 Answer

Changing 2d Destination by angle 1 Answer

How to flip 2d character walk movement? 3 Answers

Making a child object circulate/orbit around another object using mouseposition 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