Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I’m engaged on a rhythm primarily based android recreation comparable like Guitar Hero.

I’ve a kinematic rigidbody transferring downwards with tapobjects (colliders) inside which have to be pressed when moved above the button.

The massive drawback: doesnt matter what im making an attempt, i cant get the primary motion of the rigidbody to be aligned with the precise begin of the music. There’s at all times a delay of round 100ms and extra.

Intialization:

void Begin()
{
    velocity = beatTempo / 60f;
    startDelayedBy = 0f;
    setupAudioInputLag = false;
    firstFixedUpdate = false;
    songLag = 0.0692f;   // time in seconds when first beat happens of the audio
    songLagStep = ( beatTempo / 60f ) * songLag; // calculate the gap of songlag on y axis
    velocityAdd = new UnityEngine.Vector3(0f, -velocity, 0f); 
}

What i attempted, Instance 1:

non-public void FixedUpdate()
{
    if (setupAudioInputLag == false)
    {
        beatMusic.PlayDelayed(1f);
        rb.place = new UnityEngine.Vector3(rb.place.x, 0f + songLagStep, rb.place.z);
        setupAudioInputLag = true;
    }
    if (startDelayedBy >= 1f) 
    {
        rb.MovePosition(rb.place + (velocityAdd * Time.fixedDeltaTime));
    }
    if (setupAudioInputLag)
    {
        startDelayedBy += Time.fixedDeltaTime;
    }
}

Instance 2:

non-public void Replace()
{
    getAccurateDspStart = AudioSettings.dspTime;
    if (setupAudioInputLag == false)
    {
        beatMusic.PlayScheduled(AudioSettings.dspTime + 1.0f);
        dspTimeStore = AudioSettings.dspTime + 1.0f;
        rb.place = new UnityEngine.Vector3(rb.place.x, 0f + songLagStep, rb.place.z);
        setupAudioInputLag = true;
    }
}

non-public void FixedUpdate()
{
    if (getAccurateDspStart >= (dspTimeStore) && setupAudioInputLag) 
    {
        rb.MovePosition(rb.place + (velocityAdd * Time.fixedDeltaTime));
    }
}

Instance 3:

non-public void Replace()
{
    getAccurateDspStart = Time.time;
    getAccurateDspStartOld = AudioSettings.dspTime;
}

non-public void FixedUpdate()
{
    accurateDspTime = getAccurateDspStartOld + (Time.time - getAccurateDspStart);
    if (accurateDspTime != 0f)
    {
        if (setupAudioInputLag == false)
        {
            beatMusic.PlayScheduled(accurateDspTime + 1.0f);
            dspTimeStore = accurateDspTime + 1.0f;
            rb.place = new UnityEngine.Vector3(rb.place.x, 0f + songLagStep, rb.place.z);
            setupAudioInputLag = true;
        }
    }
    if (accurateDspTime >= (dspTimeStore) && setupAudioInputLag)  
    {
        rb.MovePosition(rb.place + (velocityAdd * Time.fixedDeltaTime));
    }
}

And rather more i attempted over a number of days witouth even shut of success. I would like accuracy about 10-20ms.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *