-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalkBetter.cs
28 lines (22 loc) · 926 Bytes
/
WalkBetter.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WalkBetter : MonoBehaviour
{
private SteamVR_Controller.Device LeftController;
void Awake()
{
LeftController = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestLeft));
}
// Update is called once per frame
void Update ()
{
Vector2 touchpadVector = LeftController.GetAxis();
touchpadVector.Normalize();
touchpadVector /= 50;
float controllerRotation = -1 * LeftController.transform.rot.y * Mathf.PI;
float x = touchpadVector.x * Mathf.Cos(controllerRotation) - touchpadVector.y * Mathf.Sin(controllerRotation);
float z = touchpadVector.x * Mathf.Sin(controllerRotation) + touchpadVector.y * Mathf.Cos(controllerRotation);
gameObject.transform.position += new Vector3(x, 0, z);
}
}