Guest User

Untitled

a guest
Jan 4th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using Valve.VR;
  4.  
  5. public class StickMove : MonoBehaviour
  6. {
  7.     [Tooltip("input action for stick movement, e.g. left joystick")]
  8.     public SteamVR_Action_Vector2 moveAction;
  9.  
  10.     [Tooltip("input action for turning, e.g. right joystick. only the X axis is used.")]
  11.     public SteamVR_Action_Vector2 turnAction;
  12.  
  13.     [Tooltip("point around which stick turning operates. set to 'FollowHead' to turn around the HMD, e.g. like vrchat.")]
  14.     public Transform turningOrigin;
  15.  
  16.     [Tooltip("Transform to affect, e.g. the Player's playspace.")]
  17.     public Transform targetTransform;
  18.  
  19.     [Tooltip("joystick range to ignore, since usually they stick to small positive values.")]
  20.     [Range(0.0f, 1)]
  21.     public float deadZone = 0.1f;
  22.  
  23.     [Tooltip("move speed multiplier")]
  24.     [Range(0.0f, 50f)]
  25.     public float moveSpeed = 10.0f;
  26.  
  27.     [Tooltip("turn speed multiplier, in degrees")]
  28.     [Range(0.0f, 180f)]
  29.     public float turnSpeed = 50.0f;
  30.  
  31.     void Update()
  32.     {
  33.         if (moveAction.axis.magnitude > deadZone)
  34.         {
  35.             targetTransform.Translate(
  36.                 new Vector3(moveAction.axis.x, 0.0f, moveAction.axis.y) * moveSpeed * Time.deltaTime);
  37.         }
  38.  
  39.         if (Math.Abs(turnAction.axis.x) > deadZone)
  40.         {
  41.             targetTransform.RotateAround(
  42.                 turningOrigin.transform.position,
  43.                 Vector3.up,
  44.                 turnAction.axis.x * turnSpeed * Time.deltaTime);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment