- Home /
How to make rhythm game long notes?
I'm making a rhythm game for a university course and I can't figure out a way to make the long/sustained notes. For reference, this is what I mean taken from Guitar Hero:
I already have a system working for regular notes. The way I do it is that the notes are stored in an external file as numbers which represent the absence or presence of a note as well as what type of note it is, separated into musical bars:
000
010
020
001
There are three lanes for the notes to be, and this means that in this particular bar there are notes wherever it's not 0 (with the numbers being different types of notes).
I had thought of using this system to create long/sustained note start and end markers (say 3 and 4) and that create another game object which would be the line between the start and end markers. But the way my note generator works is that the notes are not all generated at once because that'd be pretty heavy.
Instead, the notes are generated at a certain time taking into account its speed so that it's instantiated and will reach the player's activator when it's supposed to. The following is a part of my note generator code, put in the Update method:
// if current song time - time offset is greater than
// time taken for all executed bars so far
// spawn the next bar's notes
if (songTimer - _timeOffset >= (barExecutedTime - barTime))
{
StartCoroutine(PlaceBar(noteData.bars[barCount++]));
barExecutedTime += barTime;
}
And here is the PlaceBar coroutine:
// go through all notes in a bar
// creates an instance of note prefab
// depending on which note is meant to be spawned
private IEnumerator PlaceBar(List<SongParser.Notes> bar)
{
for (int i = 0; i < bar.Count; i++)
{
if (IsThereNote(bar[i].bottom))
{
GameObject _obj = (GameObject) Instantiate(GetNotePrefab(bar[i].bottom, true), new Vector3(bottomLane.transform.position.x + distance, bottomLane.transform.position.y, bottomLane.transform.position.z - 0.3f), Quaternion.identity);
}
if (bar[i].middle != 0)
{
GameObject _obj = (GameObject) Instantiate(GetNotePrefab(bar[i].middle, false), new Vector3(middleLane.transform.position.x + distance, middleLane.transform.position.y, middleLane.transform.position.z - 0.3f), Quaternion.identity);
}
if (bar[i].top != 0)
{
GameObject _obj = (GameObject) Instantiate(GetNotePrefab(bar[i].top, true), new Vector3(topLane.transform.position.x + distance, topLane.transform.position.y, topLane.transform.position.z - 0.3f), Quaternion.identity);
}
yield return new WaitForSeconds((barTime / bar.Count) - Time.deltaTime);
}
}
Could anyone help please?
Do all the note numbers have 3 chars? If so why not add a 4th which would be how many points its meant to cover, and then run a check on its length and if longer than 3 split the 1st 3 from the 4th and do your logic.
Do you have a system to control beats? You may have to store 6 numbers ins$$anonymous$$d of 3. Having 3 numbers for notes and another 3 for each note's sustain, so 120, 140 would mean the left lane would play note 1 for 1 beat and the middle lane would play note 2 for 4 beats/the whole bar. This would also allow flexibility for different time signatures.