Unity revolution counter

Asked

Viewed 71 times

-1

I’m studying the game Flippy Knife, and I used Addrelativetorque to turn the knife and apply the 360 that always adds 1 point, but when trying to count the score checking if the knife has reached a certain angle, simply did not add any score (I tried several angles to see if it worked, but it didn’t work) The angle starts to zero, I made the counter run in the update, what I noticed was that in the inspector, when running the game, the rotation. x does not go from 0 to 360 for some reason, it works in a different way.

Torque code: (works as I drag the mouse)

void Launch()
{
    isInAir = true;
    knifeRb.isKinematic = false;
    knifeRb.AddForce((releasePosition - touchPosition) * launchForce, ForceMode.Impulse);
    knifeRb.AddRelativeTorque(torqueForce, ForceMode.Impulse);
}

Counter (put it in update to run):

void Contador()
{
    if (contAng.transform.rotation.eulerAngles.x == 359)
    {
        pontos++;            
    }

}

Jogo inicia com rotação no X zerada

  • I don’t understand... he’s just gonna add pontos if the angle is exactly 359?

1 answer

0

I think it would be easier for you to make an equation that calculates how many times the knife has spun instead of incrementing each time it rotates. can do something like this.

void Contador()
{
   points = (int) contAng.transform.rotation.eulerAngles.x/360     
}

You can leave this method in the update if you want to create feed backs each time the points value changes or you can call this method at the end to know how many laps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.