-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVRController.cs
More file actions
47 lines (35 loc) · 1.14 KB
/
VRController.cs
File metadata and controls
47 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
using Valve.VR.InteractionSystem;
public class VRController : MonoBehaviour
{
public float speed = 0.01f;
public GameObject head = null;
public SteamVR_Action_Single squeezeAction = SteamVR_Input.GetAction<SteamVR_Action_Single>("Squeeze");
private CharacterController characterController = null;
private void Awake()
{
characterController = GameObject.Find("Player").GetComponent<CharacterController>();
}
private void Start()
{
}
private void Update()
{
MovementHandler();
}
private void MovementHandler()
{
float forwardSpeed = squeezeAction.GetAxis(SteamVR_Input_Sources.Any);
if (forwardSpeed > 0)
{
Vector3 rotation = head.transform.rotation * Vector3.forward;
Vector2 rotationAngle = new Vector2(rotation.x, rotation.z);
rotationAngle.Normalize();
Vector3 realMove = new Vector3(rotationAngle.x * speed, 0, rotationAngle.y * speed);
characterController.Move(realMove);
}
}
}