void FixedUpdate() { if (thisController.GetButton((Valve.VR.EVRButtonId)m_buttonID)) { clicking = true; lineRenderer.enabled = true; Vector3 velocityVector = transform.forward * arcLength; #if UNITY_5_6 lineRenderer.positionCount = (int)(maxTime / timeResolution) / 2; #else lineRenderer.positionCount = (int)(maxTime / timeResolution) / 2; #endif int index = 0; Vector3 currentPosition = transform.position; for (float t = 0.0f; t < maxTime / 2; t += timeResolution) { lineRenderer.SetPosition(index, currentPosition); currentPosition += velocityVector * timeResolution; if (currentPosition.y < -1.3f) { #if UNITY_5_6 lineRenderer.positionCount -= (lineRenderer.positionCount - index); #else lineRenderer.positionCount -= (lineRenderer.positionCount - index); #endif break; } velocityVector += Physics.gravity; index++; } } else { lineRenderer.enabled = false; if (clicking == true) { #if UNITY_5_6 transform.root.position = new Vector3(lineRenderer.GetPosition(lineRenderer.positionCount - 1).x, groundLevel, lineRenderer.GetPosition(lineRenderer.positionCount - 1).z); #else transform.root.position = new Vector3(lineRenderer.GetPosition(lineRenderer.positionCount - 1).x, groundLevel, lineRenderer.GetPosition(lineRenderer.positionCount - 1).z); #endif clicking = false; } } }
void Update() { if (leftController.GetButton((Valve.VR.EVRButtonId)runButton) || rightController.GetButton((Valve.VR.EVRButtonId)runButton) && !isToggle) { zVelLeft = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).z; zVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).z; xVelLeft = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).x; xVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).x; if (swingingArmBack && motionType != eMotionType.BREAST_STROKE) { float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x; float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y; float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z; swingForce = Mathf.Max(posX, posY, posZ) * swingForceMultiplier; agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *moveSpeed *swingForce *Time.deltaTime); } else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE) { switch (swimSettings) { case eSwimSettings.FREE: { agent.enabled = false; float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x; float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y; float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z; transform.root.position += transform.forward / (moveSpeed * 12) * (Mathf.Max(posX, posY, posZ) * 4); break; } case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break; } } switch (motionType) { case eMotionType.ARM_SWING: UpdateArmSwing(); break; case eMotionType.SKIING: UpdateSkiing(); break; case eMotionType.BREAST_STROKE: UpdateBreastStroke(); break; default: Debug.LogWarning("Somehow you have no motion type set??"); break; } } else if (leftController.GetButtonDown((Valve.VR.EVRButtonId)runButton) || rightController.GetButtonDown((Valve.VR.EVRButtonId)runButton) && isToggle) { toggleOn = !toggleOn; } if (isToggle) { if (toggleOn) { if (swingingArmBack && motionType != eMotionType.BREAST_STROKE) { agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); } else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE) { switch (swimSettings) { case eSwimSettings.FREE: { agent.enabled = false; transform.root.position += transform.forward / (moveSpeed * 12); break; } case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break; } switch (motionType) { case eMotionType.ARM_SWING: UpdateArmSwing(); break; case eMotionType.SKIING: UpdateSkiing(); break; case eMotionType.BREAST_STROKE: UpdateBreastStroke(); break; default: Debug.LogWarning("Somehow you have no motion type set??"); break; } } } else { agent.velocity = Vector3.zero; #if UNITY_5_6 agent.isStopped = true; #else agent.Stop(); #endif } } }