void OnAcceleratorBegin(Collider other) { acceleratorOutPut = other.transform.root.GetComponent <AcceleratorOutput>(); acceleratorOutPut = other.GetComponentInParent <AcceleratorOutput>(); AccelerateLever = other.gameObject; AcceleratelLeverTop = AccelerateLever.transform.parent.parent.parent.transform.Find("Relative Center Point").gameObject; AcceleratorLeverAnimator = AccelerateLever.transform.parent.parent.GetComponent <Animator>(); AccelerateLeverLastBlend = AcceleratorLeverAnimator.GetFloat("Blend X"); AcceleratelLeverTop.transform.position = transform.position; AcceleratelStickLever = true; }
// Update is called once per frame void FixedUpdate() { if (SteeringWheelStick) // STEERING WHEEL CONTROLLER { if (!WheelController.Hand) { WheelController.Hand = gameObject; // CHECK IF ALREADY HAND GRABBED } WheelController.OnStick(VRJoystickTracker); } if (!VRJoystickTracker.triggerPressed) // UNSTICK EVERYTHING { UnstickEveryThing(); } if (ConrolStickLever) // CONTROL LEVER CONTROLLER { ControlleverTopRelative = ControlLeverTop.transform.InverseTransformPoint(transform.position); ControlleverAnimator.SetFloat("Blend Z", ControlleverTopRelative.z / 2); if (ControlleverAnimator.GetFloat("Blend Z") < 4.5f && ControlleverAnimator.GetFloat("Blend Z") > -4.5f) { joystickOutput.joyPitch = ControlleverAnimator.GetFloat("Blend Z"); } ControlleverAnimator.SetFloat("Blend X", ControlleverTopRelative.x / 2); if (ControlleverAnimator.GetFloat("Blend X") < 4.5f && ControlleverAnimator.GetFloat("Blend X") > -4.5f) { joystickOutput.joyRoll = ControlleverAnimator.GetFloat("Blend X"); } if (transform.localEulerAngles.y - RotateWhenPicked <= 60 && transform.localEulerAngles.y - RotateWhenPicked >= -60) { joystickOutput.joyYaw = transform.localEulerAngles.y - RotateWhenPicked; Lever.transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y - RotateWhenPicked, 0); } } if (!ConrolStickLever && ControlleverAnimator) { // UNSTICK CNROL LEVER ControlLeverLastX = ControlleverAnimator.GetFloat("Blend X"); ControlleverPosX = Mathf.Lerp(ControlLeverLastX, 0, Time.time / 150); ControlleverAnimator.SetFloat("Blend X", ControlleverPosX); joystickOutput.joyRoll = ControlleverPosX; joystickOutput.joyYaw = 0; ControlLeverLastZ = ControlleverAnimator.GetFloat("Blend Z"); ControlleverPosY = Mathf.Lerp(ControlLeverLastZ, 0, Time.time / 150); ControlleverAnimator.SetFloat("Blend Z", ControlleverPosY); joystickOutput.joyPitch = ControlleverPosY; } if (AcceleratelStickLever) // ACCELERATE LEVER CONTROLLER { AcceleratorleverTopRelative = AcceleratelLeverTop.transform.InverseTransformPoint(transform.position); AcceleratorLeverAnimator.SetFloat("Blend X", -(AcceleratorleverTopRelative.z / 40) + AccelerateLeverLastBlend); if (AcceleratorLeverAnimator.GetFloat("Blend X") > 0 && AcceleratorLeverAnimator.GetFloat("Blend X") < 0.5f) { if (acceleratorOutPut.withNegative) { acceleratorOutPut.accelAxis = (AcceleratorLeverAnimator.GetFloat("Blend X") * 4) - 1f; } else { acceleratorOutPut.accelAxis = (AcceleratorLeverAnimator.GetFloat("Blend X") * 2); } } } if (!AcceleratelStickLever && AcceleratorLeverAnimator) { // UNSTICK ACELERATE LEVER NormalizeAcceleratorBlend(); acceleratorOutPut = null; } }