Пример #1
0
    private void trackFlapping(Body body) //Basically measures the y-axis of both left and right hand of player. If the player moves the hands down at a particular pace and for a certain time, the bird will flap!
    {
        if (body.IsTracked)
        {
            currentLeftHandPositionY  = body.Joints[HandLeft].Position.Y;
            currentRightHandPositionY = body.Joints[HandRight].Position.Y;

            timer += Time.deltaTime;

            if (timer > 0.10 && Time.time > nextFlap)
            {
                if (previousLeftHandPositionY - currentLeftHandPositionY > flapthreshold && previousRightHandPositionY - currentRightHandPositionY > flapthreshold)
                {
                    if (numberOfFlaps > 0)     // To ignore the first flap, might be a better solution for this.
                    {
                        birdMovement.doFlap();
                        nextFlap = Time.time + flapRate;     // Used for cooldown, helps to prevent double triggering.
                    }
                    numberOfFlaps++;
                }
                previousLeftHandPositionY  = currentLeftHandPositionY;
                previousRightHandPositionY = currentRightHandPositionY;
                timer = 0f;
            }
        }
    }