Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.21 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class FlyingFPV : MonoBehaviour
  5. {
  6.  
  7.     public static float standardSpeed = 10.0f;
  8.     public static float fastSpeed = 15.0f;
  9.     public static float rotationSpeed = 60.0f;
  10.     public static float orientation = 0.0f;
  11.     public static float positionalSpeed = 7.5f;
  12.  
  13.     public float speed = standardSpeed;
  14.  
  15.     public GameObject CenterEyeAnchor;
  16.  
  17.     Rigidbody rb;
  18.  
  19.     void Start()
  20.     {
  21.         rb = GetComponent<Rigidbody>();
  22.         // GetComponent<Rigidbody>().isKinematic = true;
  23.     }
  24.  
  25.     void Update()
  26.     {
  27.         //Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
  28.         //Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
  29.         Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
  30.         Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
  31.         float primaryIndex = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
  32.         float secondaryIndex = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
  33.  
  34.         if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick) || OVRInput.Get(OVRInput.Button.DpadUp) ||
  35.             OVRInput.Get(OVRInput.Button.DpadDown))
  36.         {
  37.             speed = fastSpeed;
  38.         }
  39.         else
  40.         {
  41.             speed = standardSpeed;
  42.         }
  43.  
  44.         // Dpad Movement
  45.         if (OVRInput.Get(OVRInput.Button.DpadUp) || Input.GetKeyDown(KeyCode.W))
  46.         {
  47.             rb.velocity = CenterEyeAnchor.transform.forward * speed;
  48.         }
  49.         else if (OVRInput.GetUp(OVRInput.Button.DpadUp) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  50.         {
  51.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f;
  52.         }
  53.         if (OVRInput.Get(OVRInput.Button.DpadDown) || Input.GetKeyDown(KeyCode.S))
  54.         {
  55.             rb.velocity = CenterEyeAnchor.transform.forward * speed * -1;
  56.         }
  57.         else if (OVRInput.GetUp(OVRInput.Button.DpadDown) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  58.         {
  59.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f;
  60.         }
  61.         if (OVRInput.Get(OVRInput.Button.DpadRight))
  62.         {
  63.             //rb.velocity = CenterEyeAnchor.transform.right * speed;
  64.         }
  65.         else if (OVRInput.GetUp(OVRInput.Button.DpadRight) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  66.         {
  67.             //rb.velocity = CenterEyeAnchor.transform.right * 0.0f;
  68.         }
  69.         if (OVRInput.Get(OVRInput.Button.DpadLeft))
  70.         {
  71.             //rb.velocity = CenterEyeAnchor.transform.right * speed * -1;
  72.         }
  73.         else if (OVRInput.GetUp(OVRInput.Button.DpadLeft) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  74.         {
  75.             //rb.velocity = CenterEyeAnchor.transform.right * 0.0f;
  76.         }
  77.  
  78.         // Left Analog Stick Movement (Camera Face Movement)
  79.         if (primaryAxis.x != 0.0f || primaryAxis.y != 0.0f)
  80.         {
  81.             //rb.velocity = CenterEyeAnchor.transform.forward * speed * primaryAxis.y + CenterEyeAnchor.transform.right * speed * primaryAxis.x;
  82.             rb.velocity = CenterEyeAnchor.transform.forward * speed * primaryAxis.y;
  83.         }
  84.         else if (primaryAxis.x == 0.0f && primaryAxis.y == 0.0f && (OVRInput.Get(OVRInput.Button.DpadUp) == false &&
  85.             OVRInput.Get(OVRInput.Button.DpadDown) == false && OVRInput.Get(OVRInput.Button.DpadRight) == false &&
  86.             OVRInput.Get(OVRInput.Button.DpadLeft) == false) && rb.velocity.magnitude > 0)
  87.         {
  88.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f + CenterEyeAnchor.transform.right * 0.0f;
  89.         }
  90.  
  91.         // Right Analog Stick Player Rotation (This can cause player disorientation)
  92.         if (secondaryAxis.x != 0.0f)
  93.         {
  94.             //orientation = orientation + rotationSpeed * secondaryAxis.x * Time.deltaTime;
  95.             //rb.rotation = Quaternion.Euler(0, orientation, 0);
  96.         }
  97.  
  98.         // Triggers Vertical Movement (Game World Vertical Movement)
  99.         if (primaryIndex != 0.0f || secondaryIndex != 0.0f)
  100.         {
  101.             rb.velocity = transform.up * positionalSpeed * (secondaryIndex - primaryIndex);
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107. // Start of settings for Oculus Rift
  108.  
  109. /*
  110. public class FlyingFPV : MonoBehaviour
  111. {
  112.  
  113.     public static float standardSpeed = 10.0f;
  114.     public static float fastSpeed = 15.0f;
  115.     public static float rotationSpeed = 60.0f;
  116.     public static float orientation = 0.0f;
  117.     public static float positionalSpeed = 7.5f;
  118.  
  119.     public float speed = standardSpeed;
  120.  
  121.     public GameObject CenterEyeAnchor;
  122.  
  123.     Rigidbody rb;
  124.  
  125.     void Start()
  126.     {
  127.         rb = GetComponent<Rigidbody>();
  128.         // GetComponent<Rigidbody>().isKinematic = true;
  129.     }
  130.  
  131.     void Update()
  132.     {
  133.         Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
  134.         Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
  135.         float primaryIndex = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
  136.         float secondaryIndex = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
  137.  
  138.         if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick) || OVRInput.Get(OVRInput.Button.DpadUp) || OVRInput.Get(OVRInput.Button.DpadDown) || OVRInput.Get(OVRInput.Button.DpadLeft) || OVRInput.Get(OVRInput.Button.DpadRight))
  139.         {
  140.             Debug.Log("WAHAHAHA");
  141.             speed = fastSpeed;
  142.         }
  143.         else
  144.         {
  145.             speed = standardSpeed;
  146.         }
  147.  
  148.         // Dpad Movement
  149.         if (OVRInput.Get(OVRInput.Button.DpadUp) || Input.GetKeyDown(KeyCode.W))
  150.         {
  151.             rb.velocity = CenterEyeAnchor.transform.forward * speed;
  152.         }
  153.         else if (OVRInput.GetUp(OVRInput.Button.DpadUp) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  154.         {
  155.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f;
  156.         }
  157.         if (OVRInput.Get(OVRInput.Button.DpadDown) || Input.GetKeyDown(KeyCode.S))
  158.         {
  159.             rb.velocity = CenterEyeAnchor.transform.forward * speed * -1;
  160.         }
  161.         else if (OVRInput.GetUp(OVRInput.Button.DpadDown) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  162.         {
  163.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f;
  164.         }
  165.         if (OVRInput.Get(OVRInput.Button.DpadRight))
  166.         {
  167.             rb.velocity = CenterEyeAnchor.transform.right * speed;
  168.         }
  169.         else if (OVRInput.GetUp(OVRInput.Button.DpadRight) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  170.         {
  171.             rb.velocity = CenterEyeAnchor.transform.right * 0.0f;
  172.         }
  173.         if (OVRInput.Get(OVRInput.Button.DpadLeft))
  174.         {
  175.             rb.velocity = CenterEyeAnchor.transform.right * speed * -1;
  176.         }
  177.         else if (OVRInput.GetUp(OVRInput.Button.DpadLeft) && (primaryAxis.y == 0.0f && secondaryAxis.x == 0.0f))
  178.         {
  179.             rb.velocity = CenterEyeAnchor.transform.right * 0.0f;
  180.         }
  181.  
  182.         // Left Analog Stick Movement (Camera Face Movement)
  183.         if (primaryAxis.x != 0.0f || primaryAxis.y != 0.0f)
  184.         {
  185.             rb.velocity = CenterEyeAnchor.transform.forward * speed * primaryAxis.y + CenterEyeAnchor.transform.right * speed * primaryAxis.x;
  186.         }
  187.         else if (primaryAxis.x == 0.0f && primaryAxis.y == 0.0f && (OVRInput.Get(OVRInput.Button.DpadUp) == false && OVRInput.Get(OVRInput.Button.DpadDown) == false && OVRInput.Get(OVRInput.Button.DpadRight) == false && OVRInput.Get(OVRInput.Button.DpadLeft) == false) && rb.velocity.magnitude > 0)
  188.         {
  189.             rb.velocity = CenterEyeAnchor.transform.forward * 0.0f + CenterEyeAnchor.transform.right * 0.0f;
  190.         }
  191.  
  192.         // Right Analog Stick Player Rotation (This can cause player disorientation)
  193.         if (secondaryAxis.x != 0.0f)
  194.         {
  195.             orientation = orientation + rotationSpeed * secondaryAxis.x * Time.deltaTime;
  196.             rb.rotation = Quaternion.Euler(0, orientation, 0);
  197.         }
  198.  
  199.         // Triggers Vertical Movement (Game World Vertical Movement)
  200.         if (primaryIndex != 0.0f || secondaryIndex != 0.0f)
  201.         {
  202.             rb.velocity = transform.up * positionalSpeed * (secondaryIndex - primaryIndex);
  203.         }
  204.     }
  205. }
  206. */
  207.  
  208. // End of settings for Oculus Rift
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement