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;
		}
	}

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.

Hi there :slight_smile: 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 :slight_smile:

Thanks!