Example #1
0
    /// <summary>
    /// Main game loop. Checks SUKI Input, updates game time, etc.
    /// </summary>
    private void egGetSukiInput()
    {
        //print ("egGetSukiInput-------------------");
        timeSinceLastLaneMove += Time.deltaTime;

        /*
         *      float duration = Time.time - startTime;
         *      if (duration >= GameLength)  //is game time over?
         *              showGameOverPanel ();
         *      timeSinceLastLaneMove += Time.deltaTime;
         */

        //Get translated game input from SUKI
        // no-op if SUKI is not currently giving us input data

        /*NO LONGER NEED NETSKELETON TO KNOW IF CONNECTED..USES MOVEMENT FROM T-POSE INSTEAD (suki.Updating)
         * //print("Game:FixedUpdate:" + suki.Updating);
         * if (netskeleton && netskeleton.moving)
         * {
         *      print ("netskel moving:" + suki.Skeleton.Moving);
         *      suki.Skeleton.moving = true;
         *      suki.Skeleton.resetMinMax = true;
         * }
         */
        if (!suki.Updating)
        {
            print("Game:suki not updating.");
            return;
        }
//		return;
        ///
        /// Read the various Suki inputs (depending on what suki file was loaded)
        /// Below contains examples for different types of input, including joint angles, bone positions, etc.
        ///
        ///
        // read the placement range input and move the cube
        //elbow angle suki schema profile is set as "placement", but probably should use better name.
        //In X-Z movement, can be used for Z-movement together with "joystick" for X
        if (suki.RangeExists("placement"))
        {
            // we can use a range value as a placement to move left and right
            float range = suki.GetRange("placement");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (range * 2) - 1f;
            //print("placement mode:" + range + ":" + xPercent);
            // add a deadzone of +/- %
            float deadzone = 0.2f;
            if (xPercent > -deadzone && xPercent < deadzone)
            {
                xPercent = 0f;
            }
            // move the object
            Vector3 pos = PlayerObject.transform.localPosition;  //REPLACE PlayerObject with whatever object or vector you want to be updated
            pos.x = pos.x + (xPercent * Speed / 25);             // we use speed as a position scaler
            PlayerObject.transform.localPosition = pos;
        }
        //shoulder profile is set as "joystick"
        //In X-Z movement, can be used for X-movement togther with "placement" for Z.
        if (suki.RangeExists("joystick"))
        {
            // we can use a range value as a placement to move left and right
            float range = suki.GetRange("joystick");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (range * 2) - 1f;
            //print("joysick mode:" + range + ":" + xPercent);
            // move the object
            float deadzone = 0.2f;
            if (xPercent > -deadzone && xPercent < deadzone)
            {
                xPercent = 0f;
            }

            Vector3 pos = PlayerObject.transform.localPosition;  //REPLACE PlayerObject with whatever object or vector you want to be updated
            pos.z = pos.z + (xPercent * Speed / 20);             // we use speed as position scaler
            PlayerObject.transform.localPosition = pos;
        }

        //moving in discrete steps/lanes
        if (suki.SignalExists("moveLeft") && suki.SignalExists("moveRight"))
        {
            // we can use a pair of triggers to move left or move right
            bool moveLeft  = suki.GetSignal("moveLeft");
            bool moveRight = suki.GetSignal("moveRight");

            Vector3 pos = PlayerObject.transform.localPosition;

            // only if there is a direction to move, and it's been some time since our last move
            // Instead of changing the speed of the movement here we change the pause between movements
            if ((!moveLeft && !moveRight) || (moveLeft && moveRight) || (timeSinceLastLaneMove < 1 / Speed))             // we use speed as a time scaler
            {
                return;
            }
            else if (moveLeft)
            {
                pos.x = (pos.x - 0.2f);
            }
            else if (moveRight)
            {
                pos.x = (pos.x + 0.2f);
            }
            PlayerObject.transform.localPosition = pos;             //REPLACE PlayerObject with whatever object or vector you want to be updated
            timeSinceLastLaneMove = 0f;
        }
        //using foot or hand x-y position to control player position
        //You could also use each independently as Kollect does to control the hand/footprints.
        if (suki.Location2DExists("leftfoot") || suki.Location2DExists("rightfoot") || suki.Location2DExists("lefthand") || suki.Location2DExists("righthand"))
        {
            Vector2 fpos;
            if (suki.Location2DExists("leftfoot"))
            {
                fpos = suki.GetLocation2D("leftfoot");
            }
            else if (suki.Location2DExists("rightfoot"))
            {
                fpos = suki.GetLocation2D("rightfoot");
            }
            else if (suki.Location2DExists("lefthand"))
            {
                fpos = suki.GetLocation2D("lefthand");
            }
            else if (suki.Location2DExists("righthand"))
            {
                fpos = suki.GetLocation2D("righthand");
            }
            else
            {
                fpos = new Vector2();
            }
            Vector3 pos = PlayerObject.transform.localPosition;             //REPLACE PlayerObject with whatever object or vector you want to be updated
            // convert 0f to 1f to -1f to 1f
            float xPercent = (fpos.x * 2) - 1f;
            float yPercent = (fpos.y * 2) - 1f;
            float weight   = 10f;
            pos.x = (pos.x * (weight - 1) + (xPercent * Speed * 4)) / weight;       // we use speed as position scaler
            pos.y = (pos.y * (weight - 1) + (yPercent * Speed * 4)) / weight;       // we use speed as position scaler
            //pos.x = pos.x + (fpos.x * Speed/40); // we use speed as position scaler
            //PlayerObject.transform.position = Vector3.Lerp(LeftFoot.transform.position, new Vector3(newX, newY, newZ), 1f);
            PlayerObject.transform.localPosition = pos;
        }
        //checkRange ();
    }
Example #2
0
    private void FixedUpdate()
    {
        if (gameOver)
        {
            return;
        }
        if (!gameStarted)
        {  //is level just starting?
            gameStarted = true;
            startTime   = Time.time;
            //egBeginSession ();
            Tracker.Instance.BeginTracking();
            print("BEGIN TRACKING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        }
        float duration = Time.time - startTime;

        if (duration >= GameLength)  //is game time over?
        //showGameOverPanel();
        {
            timeSinceLastLaneMove += Time.deltaTime;
        }

        // no-op if SUKI is not currently giving us input data
        //print("Game:FixedUpdate:" + suki.Updating);

        if (netskeleton && netskeleton.moving)
        {
            suki.Skeleton.Moving      = true;
            suki.Skeleton.resetMinMax = true;
        }

        if (!suki.Updating)
        {
            print("Game:suki not updating.");
            return;
        }

        if (suki.RangeExists("placement"))
        {
            // we can use a range value as a placement to move left and right
            float range = suki.GetRange("placement");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (range * 2) - 1f;
            //print("placement mode:" + range + ":" + xPercent);
            // add a deadzone of +/- %
            float deadzone = 0.2f;
            if (xPercent > -deadzone && xPercent < deadzone)
            {
                xPercent = 0f;
            }
            // move the object
            Vector3 pos = PlayerObject.transform.localPosition; //REPLACE PlayerObject with whatever object or vector you want to be updated
            pos.x = pos.x + (xPercent * Speed / 20);            // we use speed as a position scaler
            PlayerObject.transform.localPosition = pos;
        }
        //shoulder profile is set as "joystick"
        //In X-Z movement, can be used for X-movement togther with "placement" for Z.
        if (suki.RangeExists("joystick"))
        {
            // we can use a range value as a placement to move left and right
            float range = suki.GetRange("joystick");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (range * 2) - 1f;
            //print("joysick mode:" + range + ":" + xPercent);
            // move the object
            float deadzone = 0.2f;
            if (xPercent > -deadzone && xPercent < deadzone)
            {
                xPercent = 0f;
            }
            Vector3 pos = PlayerObject.transform.localPosition; //REPLACE PlayerObject with whatever object or vector you want to be updated
            pos.z = pos.z + (xPercent * Speed / 25);            // we use speed as position scaler
            PlayerObject.transform.localPosition = pos;
        }

        if (suki.SignalExists("moveLeft") && suki.SignalExists("moveRight"))
        {
            // we can use a pair of triggers to move left or move right
            bool moveLeft  = suki.GetSignal("moveLeft");
            bool moveRight = suki.GetSignal("moveRight");

            Vector3 pos = PlayerObject.transform.localPosition;

            // only if there is a direction to move, and it's been some time since our last move
            // Instead of changing the speed of the movement here we change the pause between movements
            if ((!moveLeft && !moveRight) || (moveLeft && moveRight) || (timeSinceLastLaneMove < 1 / Speed)) // we use speed as a time scaler
            {
                return;
            }
            else if (moveLeft)
            {
                pos.x = (pos.x - 0.2f);
            }
            else if (moveRight)
            {
                pos.x = (pos.x + 0.2f);
            }
            PlayerObject.transform.localPosition = pos;
            timeSinceLastLaneMove = 0f;
        }
        if (suki.Location2DExists("leftfoot"))
        {
            Vector3 pos  = PlayerObject.transform.localPosition; //REPLACE PlayerObject with whatever object or vector you want to be updated
            Vector2 fpos = suki.GetLocation2D("leftfoot");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (fpos.x * 2) - 1f;
            float yPercent = (fpos.y * 2) - 1f;
            pos.x = (xPercent * Speed * 4); // we use speed as position scaler
            pos.y = (xPercent * Speed * 4); // we use speed as position scaler
            PlayerObject.transform.localPosition = pos;

            //pos.x = pos.x + (fpos.x * Speed/40); // we use speed as position scaler
            //PlayerObject.transform.position = Vector3.Lerp(LeftFoot.transform.position, new Vector3(newX, newY, newZ), 1f);
        }
        if (suki.Location2DExists("rightfoot"))
        {
            Vector3 pos  = PlayerObject.transform.localPosition; //REPLACE PlayerObject with whatever object or vector you want to be updated
            Vector2 fpos = suki.GetLocation2D("rightfoot");
            // convert 0f to 1f to -1f to 1f
            float xPercent = (fpos.x * 2) - 1f;
            float yPercent = (fpos.y * 2) - 1f;
            pos.x = (xPercent * Speed * 4); // we use speed as position scaler
            pos.y = (yPercent * Speed * 4); // we use speed as position scaler
            PlayerObject.transform.localPosition = pos;
        }
        checkRange();
    }