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 SmileQ · Nov 15, 2013 at 02:54 PM · updateframeratereplay

Replay system for android, need help with precision (framerate problem)

I have a simple replay system to "replay" the game. (the game I'm making is for android)

It's made so that it saves the positions of two joysticks to a file when recording, and when playing back it reads those positions and sets them to the joysticks.

Now the replay system "works", but if I play for a couple of minutes, I lose some of the accuracy (e.g. if in recording my last position was (14, 1, 14), when playing back it varies by -1, +1). I'm guessing this is because the framerate of the game keeps changing.

I don't have much experience with Unity so I'm wondering how I should go about fixing this.. So far I've tried setting the targetFramerate of the application, but that dosn't seem to help.

The closest I've goten is by setting Time.captureFramerate, the variaton then was in decimals, about 0.2 after two minutes, but I don't think this is an option on weaker devices + (messy?).

Now I need someone to give me a nudge in the right direction, or atleast to tell me that making this 100% accurate is impossible. Below is how the reply system works:

 Recording..
 - Start a Coroutine that saves position every frame
     Coroutine:
     - keep running while recording
     - calls a couple of simple functions, that save the joysticks positions to arrays and later to a file
     - has a yierd return null (every frame?)
     
 Playing recording..
 - Start 3 Coroutines
     1. Coroutine reads the positions from a text file and fills the two arrays
     - keep running until EOF (replay file)
     - reads positions from text and fills arrays
     - has a yield return null
     
     2. Coroutine reads information from the arrays and sets the position of joysticks
     - keep running while array has "something" inside ( I use a queue for the array, POPing and PUSHing )
     - reads from array and sets joystick position
     - has a yield return null
     
     3. Coroutine, this one is the same as the second one, just a diffrent joystick
     

(The joysticks that I'm reading positions from are the joysticks from the Standard Assets (Mobile) package, if I understand correctly they only change positions every frame).

EDIT: The write, read is working fine. ( every value that gets writen, later gets read)

Comment
Add comment · Show 3
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 Benproductions1 · Nov 16, 2013 at 07:48 AM 0
Share

Evaluating Physics/collision and doing any sort of floating point work you always have a certain margin of error. Because of simplifications that allow things to be done in real-time, nothing will ever really happen the exact same way.

I suggest ins$$anonymous$$d of saving the "input", you save the "output" aka the position of objects and interpolate.

avatar image SmileQ · Nov 16, 2013 at 01:39 PM 0
Share

Yeah I realize that physics always give some error, but the game I'm making is being designed so that it barely uses any physics.

Anyways, the problem here is framerate-wise since if I keep the framerate at a constant I get almost no error, but the bigger the variation of framerate the bigger the error.

I'm just looking for a way to make this framerate independant.

avatar image Benproductions1 · Nov 16, 2013 at 09:13 PM 0
Share

Why not just use the physics loop then?

1 Reply

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

Answer by SmileQ · Nov 18, 2013 at 11:49 AM

Nevermind, I got it to work. Yeah I did try using the physics loop before but it didn't work, now I finnaly realized why not.. I forgot to change the joysticks position update loop into a physics loop.

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

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

18 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

Related Questions

Fixedupdate rate stays at 90 instead of 60 1 Answer

Is Update() NOT linked with graphics refresh rate? 3 Answers

higher frame-rate than update frame-rate 1 Answer

How does Time.deltaTime provide smoother physics functions? (Frame rate question) 2 Answers

Getting Input every few frames? 2 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