808 beats

For a bit of fun I started playing with an idea to make a drum machine in Unity, with the obligatory 16 step beat sequencer.

The way I’ve started is to make a strip of sixteen buttons which the user can toggle on and off by tapping. The buttons are just cubes currently and tapping is detected by RayCasting.

I move a ‘beat marker’ along the sequence strip and every time it enters a button’s Trigger it fires off the drum sound. The last button in the strip sends a message OnTriggerExit to reset the beat marker to the start.

This works pretty well, though I don’t think the timing is quite tight enough.

Does anyone have a suggestion about a better way to do this - maybe I shouldn’t be getting my timing from moving the beat marker?

I definitely wouldn’t use triggers for this; I’d let the beat marker just be a visual that reflected the current time, rather than having it actually drive playback via trigger events.

That said, from everything I’ve read I get the impression that the current version of Unity isn’t particularly well suited for music applications or rhythm-oriented games, as it’s difficult to achieve the kind of precise timing that’s required. (Maybe this will change in Unity 3, but I don’t know one way or the other whether that’s the case.)

Yeah, I think my approach was a bit backward. It almost works in the editor but the timing is terrible on the device itself… definitely not a constant speed even using Time.deltaTime… it can be almost a whole second out sometimes! I’m not sure why it hangs so often, as I’m not instantiating anything and only running one short update loop. Still, performance on my 3G is much worse since OS4. I may try your suggestion and run it from a timer rather than relying on triggers… sounds a lot more sensible.

Hello OMG
I have made something like this in a game once. are Are all the BPM the same?
Do thay hit all on time.Means was tested out side unity?
Sometimes lag can make it go out of time.
But i must say sounds very cool.

Hello OMG
I have made something like this in a game once. are Are all the BPM the same?
Do thay hit all on time.Means was tested out side unity?
Sometimes lag can make it go out of time.
But i must say sounds very cool.

For what it’s worth I found using triggers in this way gave the following results:

yes, different sounds on the same step fired at exactly the same time.

No, it doesn’t keep good enough timing - there are gaps and lags.

Jesse’s suggestion of setting up a timer and using the graphics simply to represent this would definitely produce better results. I may try it when I get some spare time again :slight_smile: