コード例 #1
0
    void Update()
    {
        //Directions obtained from CC_CANOE class. We use the Right wand and Head for orientation.
        //Where the right wand is pointed is the direction the player will move
        Vector3 forwardDir = CC_CANOE.WandGameObject(Wand.Right).transform.forward;
        Vector3 rightDir   = CC_CANOE.HeadGameObject().transform.right;

        rightDir = Vector3.Normalize(Vector3.ProjectOnPlane(rightDir, Vector3.up));
        Vector3 upDir = Vector3.up;

        //The input from the trigger axis of the left wand
        float forward = CC_INPUT.GetAxis(Wand.Right, WandAxis.Trigger);

        //Move the CharacterController attached to the CC_CANOE.
        Vector3 movement = forwardDir * forward;

        charCont.Move(movement * Time.deltaTime * moveSpeed);

        //The input from the X and Y axis of the right wand joystick.
        yAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.XAxis) * Time.deltaTime * lookSpeed;
        yAxisChange  = yAxisChange % 360.0f;
        xAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.YAxis) * Time.deltaTime * lookSpeed;
        xAxisChange  = Mathf.Clamp(xAxisChange, -maxPitch, maxPitch);

        //Change the direction the CharacterController is facing.
        charCont.transform.rotation = Quaternion.identity;
        charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, Vector3.up, yAxisChange);
        charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, rightDir, xAxisChange);
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //Head tracking
        Transform source = CC_CANOE.HeadGameObject().transform;

        headReference.transform.position      = convertPosition(source.position);
        headReference.transform.localRotation = convertRotation(source.rotation);

        //Left wand tracking
        source = CC_CANOE.WandGameObject(Wand.Left).transform;
        leftWandReference.transform.position      = convertPosition(source.position);
        leftWandReference.transform.localRotation = convertRotation(source.rotation);

        //Right wand tracking
        source = CC_CANOE.WandGameObject(Wand.Right).transform;
        rightWandReference.transform.position      = convertPosition(source.position);
        rightWandReference.transform.localRotation = convertRotation(source.rotation);

        //Waist tracking
        waistReference.transform.localPosition = convertPuckPosition(waistReference.transform.localPosition, 0);
        waistReference.transform.localRotation = convertPuckRotation(0);

        //Left foot tracking
        leftFootReference.transform.localPosition = convertPuckPosition(leftFootReference.transform.localPosition, 1);
        leftFootReference.transform.localRotation = convertPuckRotation(1);

        //Right foot tracking
        rightFootReference.transform.localPosition = convertPuckPosition(rightFootReference.transform.localPosition, 2);
        rightFootReference.transform.localRotation = convertPuckRotation(2);
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        projectile.transform.position = new Vector3(wandTransform.position.x,
                                                    wandTransform.position.y,
                                                    wandTransform.position.z);
        permanentTrail.transform.position = projectile.transform.position;

        if (CC_INPUT.GetButtonDown(wand, WandButton.Trigger))
        {
            GameObject tempProjectile = Instantiate(projectile);
            tempProjectile.AddComponent <DestroyProjectile>();
            tempProjectile.GetComponent <Rigidbody>().isKinematic = false;
            tempProjectile.GetComponent <Rigidbody>().AddForce(CC_CANOE.WandGameObject(wand).transform.forward *projectileForce);
        }
    }
コード例 #4
0
    void Start()
    {
        //Instantiate an empty object to be used as ray origin. This is needed to avoid colliding with
        //the sphere collider on the wand before it can collide with the color wheel.
        leftRayOrigin  = Instantiate(new GameObject(), CC_CANOE.WandGameObject(Wand.Left).transform);
        rightRayOrigin = Instantiate(new GameObject(), CC_CANOE.WandGameObject(Wand.Right).transform);
        leftRayOrigin.transform.localPosition = rightRayOrigin.transform.localPosition = offset;

        lineCount1 = 0;
        lineCount2 = 0;
        leftColor  = new Color(1, 0.88f, 0.49f);
        rightcolor = new Color(0.94f, 0.28f, 0.13f);

        //Setup the line pointers.
        linePointer1.positionCount = 0;
        linePointer1.startWidth    = 0.01f;
        linePointer1.endWidth      = 0.01f;
        linePointer2.positionCount = 0;
        linePointer2.startWidth    = 0.01f;
        linePointer2.endWidth      = 0.01f;
    }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();

        controller = CC_CANOE.CanoeCharacterController();

        parentTransform    = transform.GetComponentInParent <Transform>();
        headTransform      = CC_CANOE.HeadGameObject().gameObject.transform;
        leftHandTransform  = CC_CANOE.WandGameObject(Wand.Left).gameObject.transform;
        rightHandTransform = CC_CANOE.WandGameObject(Wand.Right).gameObject.transform;

        //Initial call to chest puck
        VRPN.vrpnTrackerQuat("CC_FLAT_PUCK0@" + CC_CONFIG.innovatorIP, 0);

        //Brings model out of ground
        offset = new Vector3(0, 2f * transform.GetChild(0).GetComponent <SkinnedMeshRenderer>().bounds.extents.x, 0);
        transform.localPosition = offset;

        leftMirrorGoal  = transform.parent.GetChild(1).transform;
        rightMirrorGoal = transform.parent.GetChild(2).transform;
    }
コード例 #6
0
 // Use this for initialization
 void Start()
 {
     wandTransform = CC_CANOE.WandGameObject(wandToFollow).transform;
 }
コード例 #7
0
    void FixedUpdate()
    {
        if (!enableNavigation)
        {
            return;
        }

        //Save wand model
        savedWandModel = canoe.wandModel;

        //If we are using the trigger button to navigate check if it is pressed.
        if (navWithTrigger)
        {
            if (CC_INPUT.GetAxis(wandToUse, WandAxis.Trigger) > 0.0f)
            {
                doNav         = true;
                endNavUpdated = false;
            }
            else
            {
                doNav = false;
            }
        }
        else
        {
            //Otherwise check the chosen wand button
            doNav         = CC_INPUT.GetButtonPress(wandToUse, navButton);
            endNavUpdated = false;
        }

        if ((resetButton == navButton) && (!navWithTrigger))
        {
            print("CCaux_OmniNavigator Warning: Chosen Navigation and Reset Navigation buttons are the same.");
        }

        //Gradually resets canoe position and rotation
        if (CC_INPUT.GetButtonPress(wandToUse, resetButton))
        {
            charCont.transform.position = Vector3.Slerp(charCont.transform.position, resetPosition, resetSpeed * Time.deltaTime);
            charCont.transform.rotation = Quaternion.Slerp(charCont.transform.rotation, resetAngle, resetSpeed * Time.deltaTime);
        }

        //Disables the cursor and re-enables the wand models ONCE
        if (!doNav && !endNavUpdated)
        {
            doneNav         = false;
            canoe.wandModel = savedWandModel;
            cursor.SetActive(false);
            canoe.UpdateWandModels();
            endNavUpdated = true;
        }

        if (doNav)
        {
            // If wand button pressed the first time then record the starting position and orientation of the wand
            if (doneNav == false)
            {
                startPosition = CC_CANOE.WandGameObject(wandToUse).transform.localPosition;

                doneNav       = true;
                startRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation;
            }
            else
            {
                // Then at each time check the difference between new and old wand position as well as new and old wand orientation.
                // Apply that difference to the character controller to effect navigation.
                Vector3 movement = CC_CANOE.WandGameObject(wandToUse).transform.localPosition - startPosition;

                // If disable navigation in a particular axis is enabled then set movement values to zero.
                if (disableNavigationX)
                {
                    movement.x = 0;
                }
                if (disableNavigationY)
                {
                    movement.y = 0;
                }
                if (disableNavigationZ)
                {
                    movement.z = 0;
                }

                movement = gameObject.transform.localRotation * movement; // Movement must take into account current orientation of CyberCANOE

                charCont.Move(movement * Time.deltaTime * moveSpeed);

                Quaternion newRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation;

                // Check if a rotation lock is enabled and handle it
                float      axisLockAngle;
                Quaternion rotator = new Quaternion();

                switch (lockRotation)
                {
                case rotationLock.X:
                    axisLockAngle             = newRotation.eulerAngles.x;
                    rotator.eulerAngles       = new Vector3(axisLockAngle, 0, 0);
                    startRotation.eulerAngles = new Vector3(startRotation.eulerAngles.x, 0, 0);
                    break;

                case rotationLock.Y:
                    axisLockAngle             = newRotation.eulerAngles.y;
                    rotator.eulerAngles       = new Vector3(0, axisLockAngle, 0);
                    startRotation.eulerAngles = new Vector3(0, startRotation.eulerAngles.y, 0);
                    break;

                case rotationLock.Z:
                    axisLockAngle             = newRotation.eulerAngles.z;
                    rotator.eulerAngles       = new Vector3(0, 0, axisLockAngle);
                    startRotation.eulerAngles = new Vector3(0, 0, startRotation.eulerAngles.z);
                    break;

                default:
                    rotator = newRotation;
                    break;
                }

                charCont.transform.localRotation = charCont.transform.localRotation * Quaternion.Slerp(Quaternion.identity, Quaternion.Inverse(startRotation * Quaternion.Inverse(rotator)), Time.deltaTime * rotateSpeed);

                // If there is a cursor object then orient it with the wand position.
                if (cursor)
                {
                    cursor.SetActive(true);
                    cursor.transform.position = CC_CANOE.WandGameObject(wandToUse).transform.position;
                    cursor.transform.rotation = CC_CANOE.WandGameObject(wandToUse).transform.rotation;
                    canoe.DeactivateModels();
                }
            }
        }
    }
コード例 #8
0
    void Update()
    {
        //Set grab setting
        grab = false;
        if (enableGrabbing)
        {
            if (grabWithTrigger)
            {
                if (CC_INPUT.GetAxis(wand, WandAxis.Trigger) > 0.0f)
                {
                    grab = true;
                }
                else
                {
                    grab = false;
                }
            }
            else
            {
                grab = CC_INPUT.GetButtonPress(wand, grabButton);
            }
        }

        if (grab)
        {
            if (grabbedObject == null)
            {
                if (currentObject != null)
                {
                    grabbedObject = currentObject;
                    // If object had a rigidbody, grabbed save the rigidbody's kinematic state
                    // so it can be restored on release of the object
                    Rigidbody body = null;
                    body = grabbedObject.GetComponent <Rigidbody>();
                    if (body != null)
                    {
                        wasKinematic     = body.isKinematic;
                        body.isKinematic = true;
                    }

                    // Save away to original parentage of the grabbed object
                    grabbedObjectParent = grabbedObject.transform.parent;

                    // Make the grabbed object a child of the wand
                    grabbedObject.transform.parent = CC_CANOE.WandGameObject(wand).transform;
                    currentObject = null;

                    // Disable collision between yourself and the grabbed object so that the grabbed object
                    // does not apply its physics to you and push you off the world
                    Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), true);
                }
            }
        }
        else
        {
            if (grabbedObject != null)
            {
                // Restore the original parentage of the grabbed object
                grabbedObject.transform.parent = grabbedObjectParent;

                // If object had a rigidbody, restore its kinematic state
                Rigidbody body = null;
                body = grabbedObject.GetComponent <Rigidbody>();
                if (body != null)
                {
                    body.isKinematic = wasKinematic;
                }

                //Re-enstate collision between self and object
                Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), false);

                grabbedObject = null;
                currentObject = null;
            }
        }
    }