Esempio n. 1
0
    void Update()
    {
        //Quaternion newRotation = Quaternion.FromToRotation(sitSki.rotation.eulerAngles, Camera.main.transform.forward);
        //Vector3 oldRotation = sitSki.rotation.eulerAngles;
        //oldRotation.y = Camera.main.transform.rotation.y;
        //sitSki.rotation = Quaternion.Euler(oldRotation);

        //sitSki.rotation = new Quaternion(sitSki.rotation.x, Camera.main.transform.rotation.y, sitSki.rotation.z, sitSki.rotation.w);

        if (!usingTracker)
        {
            SteamVR_Action_Boolean forward = SteamVR_Actions._default.forward;
            // move = forward.GetLastState(SteamVR_Input_Sources.LeftHand) || forward.GetLastState(SteamVR_Input_Sources.RightHand);
            // movement = Camera.main.transform.forward;

            //sitSki.rotation = Quaternion.FromToRotation(sitSki.rotation.eulerAngles, Camera.main.transform.forward);
            //Vector3 rotation = sitSki.eulerAngles;
            //rotation.z += 180;
            //sitSki.rotation = Quaternion.Euler(rotation);

            if (forward.GetLastState(SteamVR_Input_Sources.LeftHand) || forward.GetLastState(SteamVR_Input_Sources.RightHand) && rb.velocity.x < velMax && rb.velocity.y < velMax && rb.velocity.z < velMax)
            {    //    //transform.position = transform.position + Camera.main.transform.forward * speed * Time.deltaTime;
                //rb.MovePosition(transform.position + Camera.main.transform.forward * speed * Time.deltaTime);
                Vector3 f = Camera.main.transform.forward * speed;
                f.y = 0;
                rb.AddForce(f);
            }
        }

        //Use X-axis for movement: 90 degrees is all the way forward, 270 degrees is all the way back.
        //Put the tracker on the person with "BEN!" facing the ceiling to orient properly.
        else
        {
            Debug.Log(tracker.eulerAngles.x);

            float angle = tracker.eulerAngles.x;

            if (angle > 260)
            {
                angle = 0;
            }
            else if (angle > 45)
            {
                angle = 45;
            }

            Debug.Log(angle);

            float force = 0 + (angle - 0) * (1 - 0) / (45 - 0);
            force *= speed;
            force *= 3;

            if (rb.velocity.x < velMax && rb.velocity.y < velMax && rb.velocity.z < velMax)
            {
                Vector3 f = Camera.main.transform.forward * force;
                f.y = 0;
                rb.AddForce(f);
            }
        }
    }
Esempio n. 2
0
    private void SetCollidingObject(Collider col)
    {
        // if the object we want to grab has an rigidbody
        if (!collidingObject && col.GetComponent <Rigidbody>())
        {
            collidingObject = col.gameObject;
        }

        if (grabAction.GetLastState(handType) && objectInHand == null)
        {
            // if there is an object near our hand
            if (collidingObject)
            {
                // if the object has a special action when grabbed
                if (collidingObject.GetComponent <GrablableObject>() != null)
                {
                    objectInHand    = collidingObject;
                    collidingObject = null;
                    objectInHand.GetComponent <GrablableObject>().Grab(controllerPose);
                }
                // else, we grab it has a regular object
                else
                {
                    // we check if the object we want to grab is not already grabbed by the other hand
                    if (otherHand.objectInHand == collidingObject)
                    {
                        // if so, we release the object from the other hand, and we grab it with this hand
                        otherHand.ReleaseStandardObject();
                    }
                    GrabStandardObject();
                }
            }
        }
    }
Esempio n. 3
0
    private void Update()
    {
        float sizeRatio = sizeManager.isPlayerSmall() ? smallRatio : 1f;

        Vector2 moveAxis     = moveAction.GetAxis(hand);
        Vector2 rotationAxis = rotationAction.GetAxis(hand);
        Vector3 movement     = new Vector3(moveAxis.x, 0, moveAxis.y);
        float   rot          = transform.eulerAngles.y;

        movement = Quaternion.AngleAxis(rot, Vector3.up) * movement;
        Vector3 prevVelocity = rigidBody.velocity;
        Vector3 nextVelocity = prevVelocity + movement * acceleration * sizeRatio * Time.deltaTime;

        if (nextVelocity.magnitude <= maxWalkSpeed * sizeRatio)
        {
            rigidBody.velocity = nextVelocity; //TODO this could be bad if verticle speed is too high and then you can't move horizontally
        }

        Vector3    rotation      = new Vector3(0, rotationAxis.x, 0);
        Quaternion deltaRotation = Quaternion.Euler(rotation * turnSpeed * Time.deltaTime);

        rigidBody.MoveRotation(rigidBody.rotation * deltaRotation);

        //Check for jump
        if (!jumpAction.GetLastState(hand) && jumpAction.GetState(hand) && IsGrounded())
        {
            Jump(sizeRatio);
        }
    }
Esempio n. 4
0
 void Update()
 {
     if (Finger.GetLastState(Hand_Type))
     {
         Instantiate(Bullet, emp_.transform.position);
     }
 }
Esempio n. 5
0
 void Update()
 {
     if (Finger.GetLastState(Hand_Type))
     {
         Laser.SetActive(true);
     }
     else
     {
         Laser.SetActive(false);
     }
 }
Esempio n. 6
0
 private void Update()
 {
     if (tableSetButton.GetLastState(otherHand.input) && tableSetButton.GetLastStateDown(input))
     {
         GameManager.inst.table.transform.position += new Vector3(0, transform.position.y - GameManager.inst.table.transform.position.y, 0);
     }
     if (!grabbingObject && collidingCand.Count > 0)
     {
         collidingObject = collidingCand[0];
         collidingObject.GetComponent <Outline>().enabled = true;
     }
     if (grabButton.GetLastStateDown(input))
     {
         if (!grabbingObject && collidingObject)
         {
             grabbingObject = collidingObject;
             grabbingObject.GetComponent <Rigidbody>().isKinematic = true;
             if (otherHand.grabbingObject == grabbingObject)
             {
                 otherHand.DropObject();
             }
             collidingObject = null;
             collidingCand.Clear();
             grabbingObject.GetComponent <Outline>().enabled = false;
             if (grabbingObject.layer.Equals(LayerMask.NameToLayer("Weapon")))
             {
                 grabbingObject.GetComponentInChildren <LineRenderer>().enabled = true;
             }
             conModel.SetActive(false);
         }
         else
         {
             DropObject();
         }
         GetComponent <AudioSource>().Play();
     }
     if (grabbingObject)
     {
         grabbingObject.transform.position = transform.position + grabbingObject.GetComponent <GrabbableObject>().pos;
         grabbingObject.transform.rotation = transform.rotation;
         grabbingObject.transform.Rotate(grabbingObject.GetComponent <GrabbableObject>().angle);
         if (hairButton.GetLastStateDown(input))
         {
             grabbingObject.GetComponent <GrabbableObject>().HairTrigger();
             if (grabbingObject.layer.Equals(LayerMask.NameToLayer("Panel")))
             {
                 grabbingObject = null;
                 conModel.SetActive(true);
             }
         }
     }
 }
Esempio n. 7
0
 void Update()
 {
     if (Index_Finger.GetLastStateDown(Hand_type))
     {
         print("XXXX" + Hand_type);
     }
     if (Index_Finger.GetLastState(Hand_type))
     {
         print("XXXX" + Hand_type);
         Laser.SetActive(true);
     }
     if (Index_Finger.GetLastStateUp(Hand_type))
     {
         print("XXXX" + Hand_type);
         Laser.SetActive(false);
     }
 }
Esempio n. 8
0
    //#if ZED_STEAM_VR
#if ZED_SVR_2_0_INPUT
    /// <summary>
    /// Checks the button state of a given SteamVR boolean action.
    /// </summary>
    /// <param name="state">Whether to check if the button/action is just pressed, just released, or is being held down.</param>
    protected bool CheckSteamVRBoolActionState(SteamVR_Action_Boolean action, ControllerButtonState buttonstate)
    {
        switch (buttonstate)
        {
        case ControllerButtonState.Down:
            return(action.GetLastStateDown(GetSteamVRInputSource()));

        case ControllerButtonState.Held:
            return(action.GetLastState(GetSteamVRInputSource()));

        case ControllerButtonState.Up:
            return(action.GetLastStateUp(GetSteamVRInputSource()));

        default:
            return(false);
        }
    }
Esempio n. 9
0
        public override bool GetFinger(HandType hand, FingerName finger)
        {
            bool value = false;
            SteamVR_Input_Sources source = (hand == HandType.right) ? SteamVR_Input_Sources.RightHand : SteamVR_Input_Sources.LeftHand;

            switch (finger)
            {
            case FingerName.Trigger:
                value = trigger.GetLastState(source);
                break;

            case FingerName.Grip:
                value = grip.GetLastState(source);
                break;

            default:
                break;
            }
            return(value);
        }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        if (grabAction.GetLastStateDown(handType))
        {
            if (collidingObject && collidingObject.tag != "Bubble")
            {
                GrabObject();
            }
        }

        if (grabAction.GetLastStateUp(handType))
        {
            if (objectInHand)
            {
                ReleaseObject();
            }
        }

        if (teleportAction.GetLastState(handType))
        {
            RaycastHit hit;
            if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 1000))
            {
                hitPoint = hit.point;
                ShowLaser(hit);
                if (hit.collider.gameObject.tag == "Pitcher" || hit.collider.gameObject.tag == "IceCreamBowl")
                {
                    Vector3 distVec = gameObject.transform.position - hit.collider.gameObject.transform.position;
                    hit.collider.gameObject.GetComponent <Rigidbody>().velocity       = Vector3.Normalize(distVec) * 2;
                    hit.collider.gameObject.GetComponent <Rigidbody>().useGravity     = false;
                    hit.collider.gameObject.GetComponent <Rigidbody>().freezeRotation = true;
                    //hit.collider.gameObject.transform.rotation = controllerPose.transform.rotation * Quaternion.Euler(0, -90, -30);
                }
            }
        }
        else
        {
            attractor.SetActive(false);
        }
    }
 public bool isIncreasingAngle()
 {
     return(padUpAction.GetState(_controller) && !holdingGripAction.GetLastState(_controller));
 }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        float currTime = Time.realtimeSinceStartup;

        if (timer <= 0 && upTime <= 0.5f)
        {
            onCd = false;
            if (laserAction.GetLastState(handType))
            {
                upTime += currTime - lastTime;

                RaycastHit hit;
                if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 1000))
                {
                    hitPoint = hit.point;
                    ShowLaser(hit);
                    if (hit.collider.gameObject.tag == "Dispenser")
                    {
                        hit.collider.gameObject.GetComponent <BubbleDispenser>().pressButton();
                    }
                    else if (hit.collider.gameObject.tag == "Bubble")
                    {
                        hit.collider.gameObject.GetComponent <Bubble>().shootBubble();
                    }
                    else if (hit.collider.gameObject.tag == "DispenseButton")
                    {
                        hit.collider.gameObject.GetComponentInParent <FreezeMachine>().dispense();
                    }
                    else if (hit.collider.gameObject.tag == "ClearButton")
                    {
                        hit.collider.gameObject.GetComponentInParent <FreezeMachine>().clearIceCream();
                    }
                }
            }
            else if (freezeAction.GetLastState(handType))
            {
                upTime += currTime - lastTime;
                freezeTransform.position = controllerPose.transform.position;
                freezeTransform.rotation = controllerPose.transform.rotation;
                if (!freezeRay.isPlaying)
                {
                    freezeRay.Play();
                }
            }
            else
            {
                laser.SetActive(false);
            }
        }
        else
        {
            if (!onCd)
            {
                onCd   = true;
                timer  = .25f;
                upTime = 0;
            }
            laser.SetActive(false);
            timer -= currTime - lastTime;
        }
        lastTime = currTime;
    }
    void Update()
    {
        RaycastHit hit;

        if (!is_grab1 && is_tool && grabAction.GetLastState(handType))
        {
            grab_elapsed += Time.deltaTime;

            if (grab_elapsed >= 2.0f)
            {
                is_grab1 = true;
                if (current_tool.gameObject.name == "shovel_table")
                {
                    shovel_table.gameObject.SetActive(false);
                    shovel_img.gameObject.SetActive(true);
                }
                if (current_tool.gameObject.name == "brushes_table")
                {
                    brush_table.gameObject.SetActive(false);
                    brush_img.gameObject.SetActive(true);
                }
                grab_elapsed = 0.0f;
            }
        }
        else if (is_grab1 && grabAction.GetLastState(handType))
        {
            grab_elapsed += 1.0f * Time.deltaTime;

            if (grab_elapsed >= 2.0f)
            {
                is_grab1 = false;
                if (current_tool.gameObject.name == "shovel_table")
                {
                    shovel_table.transform.position = shovel_table_Pos;
                    shovel_table.transform.rotation = Quaternion.Euler(-90, 90, 0);
                    shovel_table.gameObject.SetActive(true);
                    shovel_img.gameObject.SetActive(false);
                    is_tool      = false;
                    current_tool = null;
                }
                if (current_tool.gameObject.name == "brushes_table")
                {
                    brush_table.transform.position = brush_table_Pos;
                    brush_table.transform.rotation = Quaternion.Euler(0, -90, 0);
                    brush_table.gameObject.SetActive(true);
                    brush_img.gameObject.SetActive(false);
                    is_tool      = false;
                    current_tool = null;
                }
                grab_elapsed = 0.0f;
            }
        }
        else
        {
            grab_elapsed = 0.0f;
        }

        if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 5))
        {
            if (is_grab1)
            {
                if (hit.transform.gameObject.tag == "Dig" && current_tool.gameObject.name == "shovel_table")
                {
                    canDig = true;
                    shovel_line.SetActive(true);
                    shovel_line.transform.position = new Vector3(hit.point.x, hit.point.y + 1.0f, hit.point.z);
                }
                else if (hit.transform.gameObject.tag == "Dust" && current_tool.gameObject.name == "brushes_table")
                {
                    brush_line.SetActive(true);
                    brush_line.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                    is_dust = true;
                }
                else
                {
                    canDig  = false;
                    is_dust = false;
                    shovel_line.SetActive(false);
                    brush_line.SetActive(false);
                }

                if (canDig && grabAction.GetLastStateDown(handType))
                {
                    Vector3 point_plus = new Vector3(hit.point.x, hit.point.y + 0.7f, hit.point.z);
                    Instantiate(shovel_dust, point_plus, Quaternion.Euler(0, 0, 0));
                    LowerTerrain(hit.point);
                    //anim_act = true;
                }
                if (is_dust && grabAction.GetLastStateDown(handType))
                {
                    Instantiate(brush_dust, hit.collider.gameObject.transform.position, Quaternion.Euler(0, 0, 0));
                    Destroy(hit.collider.gameObject);
                }
                if (hit.collider.gameObject.layer == 8 && grabAction.GetLastStateDown(handType))
                {
                    Des.OnDescription(hit.collider.gameObject);
                }
            }
        }
        else
        {
            shovel_line.SetActive(false);
            brush_line.SetActive(false);
        }
    }
Esempio n. 14
0
    //Handle hitbox, movement and teleportation
    void Update()
    {
        if (shouldFadeRestrictControl)
        {
            return;
        }

        //Handle hitbox
        if (Physics.Raycast(cameraTransform.position, transform.up * -1, out hit, 1000.0f, movementLayerMask))
        {
            currentPlayfieldSize.y = Mathf.Min(cameraTransform.localPosition.y, 2.0f);
            hitbox.size            = currentPlayfieldSize;
            hitbox.center          = new Vector3(0, cameraTransform.localPosition.y / 2 + 0.0125f, 0);
        }

        //Determine if the player is in bounds
        bool isCurrentlyInBounds = Physics.Raycast(cameraTransform.position + new Vector3(0, 500, 0), transform.up * -1, out hit, 1000.0f, boundsLayermask);

        if (isCurrentlyInBounds != isInBounds)
        {
            isInBounds = isCurrentlyInBounds;

            if (fadeCoroutine != null)
            {
                StopCoroutine(fadeCoroutine);
            }

            fadeCoroutine = StartCoroutine(Fade(isCurrentlyInBounds ? -1 : 1));
        }

        //Check if the player is in our designated play area
        if (Mathf.Abs(cameraTransform.localPosition.x) < currentPlayfieldSize.x / 2.0f && Mathf.Abs(cameraTransform.localPosition.z) < currentPlayfieldSize.z / 2.0f)
        {
            if (!wasHeadInArea)
            {
                wasHeadInArea = true;

                pavRenderer.material = inAreaColour;
            }
        }
        else
        {
            if (wasHeadInArea)
            {
                wasHeadInArea = false;

                pavRenderer.material = outOfAreaColour;
            }

            isValidTeleport = false;
            visualisationObject.SetActive(false);

            playerBody.velocity = Vector3.zero;

            return;
        }

        //Handle locomotion
        if (!Info.isPaused)
        {
            if (isTeleportation)
            {
                if (teleportAction.GetLastState(hand))
                {
                    if (!visualisationObject.activeInHierarchy)
                    {
                        visualisationObject.SetActive(true);
                        visualisationRenderer.material = invalidMaterial;
                    }

                    Vector3 destination = transform.position;

                    if (Physics.Raycast(handObject.transform.position, handObject.transform.forward, out hit, teleportMaxDistance, teleportLayerMask))
                    {
                        destination = new Vector3(hit.point.x, transform.position.y + hitbox.center.y, hit.point.z);
                    }
                    else
                    {
                        destination = new Vector3(handObject.transform.position.x + handObject.transform.forward.x * teleportMaxDistance, transform.position.y + hitbox.center.y, handObject.transform.position.z + handObject.transform.forward.z * teleportMaxDistance);
                    }

                    visualisationObject.transform.position   = destination;
                    visualisationObject.transform.localScale = hitbox.size;

                    RaycastHit[] hit2 = Physics.BoxCastAll(visualisationObject.transform.position, visualisationObject.transform.localScale / 2, Vector3.up * 0.01f, Quaternion.identity, 0.01f, teleportLayerMask);

                    if (hit2.Length > 0)
                    {
                        if (isValidTeleport)
                        {
                            visualisationRenderer.material = invalidMaterial;
                            isValidTeleport = false;
                        }
                    }
                    else
                    {
                        if (!isValidTeleport)
                        {
                            visualisationRenderer.material = validMaterial;
                            isValidTeleport = true;
                        }
                    }
                }
                else if (teleportAction.GetLastStateUp(hand))
                {
                    visualisationObject.SetActive(false);

                    if (isValidTeleport)
                    {
                        transform.position = new Vector3(visualisationObject.transform.position.x, transform.position.y, visualisationObject.transform.position.z);

                        isValidTeleport = false;
                    }
                }
            }
            else
            {
                movement = Vector3.Normalize(new Vector3(moveAction.GetAxis(hand).x, 0, moveAction.GetAxis(hand).y)) * movementSpeed;
                movement = rotationReference.TransformDirection(movement);

                playerBody.velocity = movement * Time.deltaTime;
            }
        }

        if (togglePause)
        {
            togglePause = false;
            Info.TogglePause();
            shouldUnpause = false;
            if (Info.isPaused == false)
            {
                menuLayout.SetActive(false);
            }
            pointer.SetActive(Info.isPaused);
        }

        //Menu + pausing
        if (menuButton.GetStateDown(hand))
        {
            menuLayout.SetActive(!Info.isPaused);
            togglePause = true;

            if (!Info.isPaused)
            {
                menuLayout.transform.position = new Vector3(transform.position.x, cameraTransform.position.y, transform.position.z) + rotationReference.transform.forward * ((currentPlayfieldSize.x + currentPlayfieldSize.z) / 4.0f);
                menuLayout.transform.LookAt(cameraTransform);
            }
        }

        //while paused
        if (Info.isPaused)
        {
            pointer.transform.position   = handObject.transform.position;
            pointer.transform.rotation   = handObject.transform.rotation;
            pointer.transform.localScale = Physics.Raycast(handObject.transform.position, handObject.transform.forward, out RaycastHit Output, 1000f, pausedLayers) ? new Vector3(0.1f, 0.1f, Output.distance / 2) : new Vector3(0.1f, 0.1f, 100f);

            //Pause menu interaction
            if ((Activate.GetStateDown(hand)))
            {
                if (Physics.Raycast(handObject.transform.position, handObject.transform.forward, out Output, 1000f, pausedLayers))
                {
                    if (Output.collider.gameObject.name == "Resume")
                    {
                        shouldUnpause = true;
                        togglePause   = true;
                    }
                    else if (Output.collider.gameObject.name == "Exit")
                    {
                        StartCoroutine(HandleQuitFade());
                    }
                    else if (Output.collider.gameObject.name == "Next")
                    {
                        cycletext(currentText + 1, 1);
                    }
                    else if (Output.collider.gameObject.name == "Previous")
                    {
                        cycletext(currentText - 1, -1);
                    }
                }
            }
        }
    }
Esempio n. 15
0
        public override void OnUpdate()
        {
            switch (triggerType)
            {
            case setTriggerType.getPress:
                var buttonDown = booleanAction.GetState(device);

                if (buttonDown)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonDown;
                break;

            case setTriggerType.getPressUp:
                var buttonDownUp = booleanAction.GetStateUp(device);

                if (buttonDownUp)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonDownUp;
                break;

            case setTriggerType.getPressDown:
                var buttonDownDown = booleanAction.GetStateDown(device);

                if (buttonDownDown)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonDownDown;
                break;

            case setTriggerType.getTouch:
                var buttonTouch = booleanAction.GetLastState(device);

                if (buttonTouch)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonTouch;
                break;

            case setTriggerType.getTouchUp:
                var buttonTouchUp = booleanAction.GetLastStateUp(device);

                if (buttonTouchUp)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonTouchUp;
                break;

            case setTriggerType.getTouchDown:
                var buttonTouchDown = booleanAction.GetLastStateDown(device);

                if (buttonTouchDown)
                {
                    Fsm.Event(sendEvent);
                }
                storeResult.Value = buttonTouchDown;
                break;
            }
        }