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
0
Question by gamedev8 · Mar 11, 2015 at 09:13 AM · c#gamespawnrhythmtimed

Rhythm Game Out of Sync (C#)

Hello, I currently have objects spawning to the beat of the music. However, when they hit the player's prompt, they are out of sync because of the time taken to travel from the left to the right of the screen.

The music is coming from the main camera, I was thinking of having 2 separate music tracks. 1 for the player to hear, which is delayed by a couple seconds, and the one that the code listens to to spawn the objects. Would this work? Any ideas how to implement this?

Thanks.

Here is how the beats are listened to/objects are spawned.

     public Transform target;
     public int minRange;
     public bool follow;
     //public Light spotlight;
     private float speed;
     public Rigidbody projectile;
     private float cooldown = 0.5f;
     public int detail = 250;
     public float amplitude = 0.2f;
     public float minValue = 1.0f;
 
 
     
     void Start () {
         
     }
     
     
     
     
     
     
     
     void Update(){
         cooldown -= Time.deltaTime;
         float[] info = new float[detail];
         AudioListener.GetOutputData(info, 0); 
         float packagedData = 0.0f;
         
         for(int x = 0; x < info.Length; x++)
         {
             packagedData += System.Math.Abs(info[x]);   
         }
         
         if (packagedData/info.Length > 0.2f && cooldown < 0) {
             cooldown = Random.Range(1f,1.5f);
             Rigidbody clone;
             clone = Instantiate (projectile, transform.position, transform.rotation) as Rigidbody; //This seems to create the clone
             clone.velocity = transform.TransformDirection(Vector3.forward * 40); //This details the velocity of the projectile
 
 
         }
         
         }
             
         }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HDX13 · Aug 25, 2017 at 02:48 PM

My take on this would be delaying the audio source playback. There are either two methods to achieve this:

 AudioSource music = FindObjectOfType<AudioSource>();
 music.PlayDelayed(delayTime);
 // or 
 music.PlayScheduled(delayTime);

Both uses seconds, but the differences are:

  • PlayDelayed is synced with the time of the game and uses float

  • PlayScheduled is synced with the AudioSettings.dspTime and uses double

Plus, make sure to set "Play On Awake" to false. And let the beat generation runs as usual.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Increasing spawn rate over time 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

LineRenderer static movement 1 Answer

Is there something more reliable than simple Triggers for something like a Rhythm Game? 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