Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// Wheel of Triumphs wheel force
- /// </summary>
- public class WOTForce : ApplyForce
- {
- private bool firstClick = true;
- public int first = 0;
- protected Vector3 rotationOffset;
- public float t;
- public Vector3 HandStartPos;
- Vector3 CurrentHandPos;
- [Header("VR Settings - VIVE")]
- public SteamVR_TrackedObject LHand;
- public SteamVR_TrackedObject RHand;
- public SteamVR_Controller.Device LDevice;
- public SteamVR_Controller.Device RDevice;
- public override void Start()
- {
- base.Start();
- originalRotation = transform.rotation;
- }
- protected override void Dragging()
- {
- print ("Dragging");
- if (!isSpinning)
- {
- /*RaycastHit hit;
- //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
- if (Physics.Raycast(ray, out hit, 1000f))
- {
- originalCollisionPosition = hit.point;
- LookAtThis(hit.point);
- }*/
- if (LDevice != null) {
- CurrentHandPos = LDevice.transform.pos;
- if ((HandStartPos.y - LDevice.transform.pos.y)>0.01f) {
- LookAtThis (LDevice.transform.pos);
- print (HandStartPos.y - RDevice.transform.pos.y);
- }
- }
- if (RDevice != null) {
- CurrentHandPos = RDevice.transform.pos;
- if ((HandStartPos.y - RDevice.transform.pos.y)>0.01f) {
- LookAtThis (RDevice.transform.pos);
- print (HandStartPos.y - RDevice.transform.pos.y);
- }
- }
- }
- //Release (); //Whoever the hell coded this is an idiot. -SolAZDev
- }
- void Update(){
- ///Working?
- if (LDevice == null && LHand != null && LHand.gameObject.activeInHierarchy) {
- LDevice = SteamVR_Controller.Input ((int)LHand.index);
- print ("I tried to get the LDevice");
- }
- if (RDevice == null && RHand != null && RHand.gameObject.activeInHierarchy) {
- RDevice = SteamVR_Controller.Input ((int)RHand.index);
- print ("I tried to get the RDevice");
- }
- //Check Press Cause ApplyForce is a little bs
- if (RDevice != null && (RDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip) || RDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- HandStartPos = RDevice.transform.pos;
- arrow.SetActive (false);
- return;
- }
- if (LDevice != null && (LDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip) || LDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- HandStartPos = LDevice.transform.pos;
- arrow.SetActive (false);
- return;
- }
- if (RDevice != null && (RDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip) || RDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- Dragging ();
- return;
- }
- if (LDevice != null && (LDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip) || LDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- Dragging ();
- return;
- }
- if (RDevice != null && (RDevice.GetPressUp(Valve.VR.EVRButtonId.k_EButton_Grip) || RDevice.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- Release ();
- }
- if (LDevice != null && (LDevice.GetPressUp(Valve.VR.EVRButtonId.k_EButton_Grip) || LDevice.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) {
- Release ();
- }
- }
- protected override void Release()
- {
- print (Vector3.Distance (HandStartPos, CurrentHandPos));
- if (Vector3.Distance (HandStartPos, CurrentHandPos) > 0.1f) {
- Vector3 rotationForce;
- if (LDevice != null) {
- rotationForce = originalMousePosition - (LHand.transform.position * 50 * (1 + (Vector3.Distance (CurrentHandPos, HandStartPos) * 2)));
- } else if (RDevice != null) {
- rotationForce = originalMousePosition - (RHand.transform.position * 50 * (1 + (Vector3.Distance (CurrentHandPos, HandStartPos) * 2)));
- } else {
- rotationForce = originalMousePosition - Input.mousePosition;
- }
- float y = rotationForce.y;
- //print(y+" is the reason y");
- if (y > 0) {
- spinCount++;
- hasSpun = true;
- GetComponent<Rigidbody> ().AddForceAtPosition (rotationForce * forceAmount, originalCollisionPosition);
- } else {
- spinCount++;
- hasSpun = true;
- GetComponent<Rigidbody> ().AddForceAtPosition (rotationForce * forceAmount, originalCollisionPosition);
- }
- lastPoint = Vector3.zero;
- }
- }
- /// <summary>
- /// Makes the object rotate with the mouse movement.
- /// </summary>
- /// <param name="point"></param>
- private void LookAtThis(Vector3 point)
- {
- point.x = 0;
- point.y -= transform.position.y;
- point.z -= transform.position.z;
- //if (firstClick)
- {
- rotationOffset = point;
- //originalMousePosition = Input.mousePosition;
- if(LDevice!=null){originalMousePosition = LHand.transform.position;}
- if(RDevice!=null){originalMousePosition = RHand.transform.position;}
- firstClick = false;
- }
- Quaternion blarg = Quaternion.FromToRotation(rotationOffset, point);
- transform.rotation = Quaternion.Slerp(transform.rotation, blarg, t);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement