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
3
Question by AlucardJay · Mar 13, 2012 at 08:55 AM · timepointfloatingrounding

Timing problem in Guitar Hero style game

I have a problem with my rythm game I just cannot work out. I shall try to explain logically.

so each beat (or fret) is 1 unit long, and when you transform.position.z -= Time.deltaTime it moves at 1 unit per second. this is great, so i have 60 bpm and 120 bpm straight from the physics.

there are 2 main vars - BPM and AdjustNotes : BPM - speed of song (beats per minute) : AdjustNotes - this is the co-efficient where the problem lies. more in a moment.

Here is the published project (keys are a s d f) : http://www.alucardj.net16.net/rythm1-1/WebPlayer.html

so change BPM to 60 and play scene. all the notes are inst'd in perfect time. change BPM to 120 and play, also the notes are happily in place.

Now change the BPM to 90 or 150 or 210(for a faster display of effect). the notes become inst'd earlier and earlier. Now change Adjust notes to 0.5 , the notes now become inst'd later.

So i have found where this co-efficient lies, but now what do i factor in to compensate for BPM's ?

I am imagining a graph (the terrible drawing as attached) , then how do I calculate AdjustNotes ???? http://www.alucardj.net16.net/rythm1-1/Adjust%20Notes%20co-efficient.jpg

and where did I get 0.499 from ?! ( Time Manager is set to 0.001, so 0.5(1/2 a beat) - 0.001 = 0.499 )

BUT the AdjustNotes value of 0.499 is incorrect too , as if the tempo is increased to 3 x 60 = 180 BPM , the notes start to lag.

I really cannot find the compounding factor, please help.

Here are all my scripts (they arn't that bad to read!) :

Song Manager : http://www.alucardj.net16.net/rythm1-1/scriptSongManager.js

Note 1 : http://www.alucardj.net16.net/rythm1-1/scriptNote1.js

Note 2 : http://www.alucardj.net16.net/rythm1-1/scriptNote2.js

Note 3 : http://www.alucardj.net16.net/rythm1-1/scriptNote3.js

Note 4 : http://www.alucardj.net16.net/rythm1-1/scriptNote4.js

Fretboard : http://www.alucardj.net16.net/rythm1-1/scriptFretboard.js

  • Edit :

I have changed the scripts so that any movement is applied After all calculations and Instantiating have been done , but it has the same effect as the question. (above script links are now to updated scripts)

I have also added a top-down view of the project , to make the problem easier to see : http://www.alucardj.net16.net/rythm1-1/rythm1-1tv.html

Song Manager script : http://www.alucardj.net16.net/rythm1-1/scriptSongManager.js

Also, with the suggestions I've received regarding multiple scripts : this is infact something I've looked at. But with the Time Manager set to 0.001 there should be less time for this compounding error to build up so drastically. And even with each coloured note having it's own script, they all move together and the error is the same with all of them. Also, the notes stay in relative position to the fretboard (on another script using the same timeScale var). So I am sure whatever is happening, it's really not the separate scripts.I'm sure it has something to to with the co-efficient that is multiplied where the calculation is done to find the 1/8 beat , and then the Instantiating of the notes within the Main script http://www.alucardj.net16.net/rythm1-1/scriptSongManager.js

e.g. I'm almost certain the problem is Here :

     function FixedUpdate() 
     {
         // set timeScale from BPM on the fly
         timeScale = (BPM / 60) * Time.deltaTime;
         
         eighthBeatTimer += timeScale;    
         
         // check if on 1/8 beat
         if (eighthBeatTimer >= AdjustNotes)
         {
             //check arrays , play notes for flagged
             if (SongPosition >= SongSheet1.length) {SongPosition = 0;}
             if (SongSheet1[SongPosition] == 1) {Instantiate (Note1, Vector3(-0.5, 0.075, 10), Quaternion.identity);}
             // other notes instantiated also , see full script 
             SongPosition++;
             eighthBeatTimer = 0.0;
         }
     }




Comment
Add comment · Show 11
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 syclamoth · Mar 13, 2012 at 09:01 AM 0
Share

Why do you have 4 different scripts for the four notes? They're exactly the same as each other!

avatar image syclamoth · Mar 13, 2012 at 09:03 AM 0
Share

And as for something actually related to your problem... you shouldn't assume that FixedUpdate is actually as 'fixed' as it claims. $$anonymous$$eep in $$anonymous$$d that it isn't actually perfect.

avatar image AlucardJay · Mar 13, 2012 at 09:06 AM 0
Share

the input for each note (a s d f) and the point (1 2 3 4), so the scripts are NOT exactly the same. I am still learning, and know there's better ways (enum). but it's working except for the compounding lag error.

true the fixed updates are not exact, but on each frame this is compensated for (timeScale = (BP$$anonymous$$ / 60) * Time.deltaTime;) timeScale var is then used on all scripts to keep sync. note - i have also changed the Time $$anonymous$$anager for fixed update loops from 0.02 to 0.001 . it seems to be managing fine.

sry, I do appreciate the comments, but i have spent days trying to work this out and am a little frustrated. am not sure whether it's where the notes are instantiated in the script, or where the timeScale is added, or if there is another factor i cannot see at work. Thx for reading anyway :)

for anyone looking at this, set the BP$$anonymous$$ to 210, it makes the lag effect appear quicker. Also if anyone wants I can do a publish from a top view. * top-down view now included in the question.

avatar image syclamoth · Mar 13, 2012 at 10:43 AM 0
Share

Well, I can't really explain your problem, but I can say that unnecessary script duplication is bound to cause you issues in the future. You should just make the key code a public variable, and change it on an instance-by-instance basis.

avatar image AlucardJay · Mar 14, 2012 at 02:30 AM 0
Share

Is it possible the problem is a Culmative Floating Point Error? http://answers.unity3d.com/questions/226901/problems-with-float-in-for.html

Show more comments

2 Replies

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

Answer by AlucardJay · Apr 15, 2012 at 06:41 AM

By golly gosh , I think I've cracked it ! Reiterating the problem helped me solve it, which is :

At the end of the FixedUpdate I was returning the var eighthBeatTimer to a fixed absolute value of 0.0;

By simply changing this line to :

     //eighthBeatTimer = 0.0;
     eighthBeatTimer -= AdjustNotes; // testing not returning to absolute value

(I also had to change AdjustNotes back to 0.5 , as it should be)

I set the BPM to 210, hit play and made a cuppa. When I came back the notes were still in perfect time and in correct relation to the fretboard.

Thankyou all who read the question, thought about it and gave suggestions.

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 AlucardJay · Apr 15, 2012 at 06:43 AM 0
Share

Now I can move on to the important part. To some that would be the graphics , but to me it's the $$anonymous$$usic =]

Woo-Hoo !

avatar image
0

Answer by Dacoke · Jul 18, 2014 at 04:21 PM

Hi there :) Unfortunately your links are dead now but I was wondering if you managed to finish it.

I am actually programming the same type of game but I would like to integrate the use of the motion controller "Leap". I would really appreciate some advice of yours :)

Thanks!

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

8 People are following this question.

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

Related Questions

Draw point with time function 1 Answer

Floating point accuracy weirdness 4 Answers

Is there a way to speed up the game more than 100 times? 1 Answer

Time does not start counting down when need to 1 Answer

Character moving 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