Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using Valve.VR;
- public class StickMove : MonoBehaviour
- {
- [Tooltip("input action for stick movement, e.g. left joystick")]
- public SteamVR_Action_Vector2 moveAction;
- [Tooltip("input action for turning, e.g. right joystick. only the X axis is used.")]
- public SteamVR_Action_Vector2 turnAction;
- [Tooltip("point around which stick turning operates. set to 'FollowHead' to turn around the HMD, e.g. like vrchat.")]
- public Transform turningOrigin;
- [Tooltip("Transform to affect, e.g. the Player's playspace.")]
- public Transform targetTransform;
- [Tooltip("joystick range to ignore, since usually they stick to small positive values.")]
- [Range(0.0f, 1)]
- public float deadZone = 0.1f;
- [Tooltip("move speed multiplier")]
- [Range(0.0f, 50f)]
- public float moveSpeed = 10.0f;
- [Tooltip("turn speed multiplier, in degrees")]
- [Range(0.0f, 180f)]
- public float turnSpeed = 50.0f;
- void Update()
- {
- if (moveAction.axis.magnitude > deadZone)
- {
- targetTransform.Translate(
- new Vector3(moveAction.axis.x, 0.0f, moveAction.axis.y) * moveSpeed * Time.deltaTime);
- }
- if (Math.Abs(turnAction.axis.x) > deadZone)
- {
- targetTransform.RotateAround(
- turningOrigin.transform.position,
- Vector3.up,
- turnAction.axis.x * turnSpeed * Time.deltaTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment