playMaker

Author Topic: [Solved] Sending events in time with music?  (Read 4562 times)

createasaurus

  • Full Member
  • ***
  • Posts: 146
[Solved] Sending events in time with music?
« on: May 03, 2015, 10:09:12 PM »
I have a game about a piano with light up keys.  There is a mode where the piano plays automatically and I want the piano keys to light up in time with my music track.

One option I've thought of is to use the Wait Action and try to eyeball the whole thing... but I worry about accuracy, and it may take a very, very long time to do.

I'm wishing there was a way to somehow open a timeline of the music track and place send event actions at the appropriate times.  Is anything like this possible?

Any general advice on how to approach this problem would be greatly appreciated.

Thank you,
createasaurus
« Last Edit: May 06, 2015, 10:21:33 PM by createasaurus »

TheBadFeeling

  • Junior Playmaker
  • **
  • Posts: 66
Re: Sending events in time with music?
« Reply #1 on: May 04, 2015, 11:33:57 AM »
Audio events would be awesome (I think there might be a plug-in that handles that in the store?!?).

I've used the Time attribute of the audio source - it tells you the running time of the sound clip. It's pretty predictable, and I haven't had any problems with it (though I've heard that the time can be off due to sound compression).

So you could set up your event to fire when the audio's time reaches certain values.

Just a suggestion. :)

/Bad
The Force is with you, young Playmaker – but you are not a C# senpai yet.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Sending events in time with music?
« Reply #2 on: May 04, 2015, 12:54:15 PM »
This asset lets you view audio on a time line and do things at a specific time https://www.assetstore.unity3d.com/en/#!/content/19779

Its made for doing cut scenes but you could just use it for audio + events

It has a few PMaker actions right now but a user is working on more- when these actions are out it should help you do what you want
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

createasaurus

  • Full Member
  • ***
  • Posts: 146
Re: Sending events in time with music?
« Reply #3 on: May 05, 2015, 10:18:47 AM »
@TheBadFeeling - I like this idea!  I want to try this!  I'm having a little trouble as I can't find the Time attribute.

1.) I select an object with an audio source in the Hierarchy.
2.) I look in the Inspector in the Audio Source tab.
3.) I cannot find a Time attribute

I really would love to try this.  Please elaborate on your steps.

Thank you in advance!
Gratefully,
Createasaurus


@monidotstrange - Thank you!  The asset does EXACTLY what I want, however...  it looks maybe too robust for me for this project.  This will be the backup plan, and I'm going to try to work it out in PlayMaker first.
Thank you again!
Createasaurus
« Last Edit: May 05, 2015, 12:09:00 PM by createasaurus »

TheBadFeeling

  • Junior Playmaker
  • **
  • Posts: 66
Re: Sending events in time with music?
« Reply #4 on: May 05, 2015, 05:21:45 PM »
You can grab the time attribute by dragging your Audio Component into the state and choosing Get property.
Then you have the opportunity to select which one of the Audio component's properties you want to get. Select time in the dropdown and store it in a float variable.

Now you can compare your new float (every frame) to a certain pre-measured time (or several different one-by-one after each other, 'til you have your piano playing).

Here's a screen of a test setup I just made. It jumps to the next state when the music reaches 0.25 playing time.

Hope it helps.
/Bad

« Last Edit: May 05, 2015, 05:26:14 PM by TheBadFeeling »
The Force is with you, young Playmaker – but you are not a C# senpai yet.

createasaurus

  • Full Member
  • ***
  • Posts: 146
Re: Sending events in time with music?
« Reply #5 on: May 06, 2015, 10:21:16 PM »
@ TheBadFeeling.  Thank you very much!  So far so good.