holopy3/Assets/Scripts/Locomotion.cs

48 lines
1.2 KiB
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class Locomotion : MonoBehaviour
{
public Transform viveCameraEye;
public SteamVR_Action_Vector2 controllerTrackpadInput = null;
private float height;
private void Start()
{
height = viveCameraEye.position.y;
Debug.Log(height);
}
void Update()
{
Vector3 eyeForward = viveCameraEye.forward;
eyeForward.y = 0;
Vector3 eyeRight = viveCameraEye.right;
eyeRight.y = 0;
//controllerTrackpadInput.GetPadTouchAxis(HandRole.RightHand);
Vector3 position = eyeForward * controllerTrackpadInput.axis.y + eyeRight * controllerTrackpadInput.axis.x;
position = position.normalized;
Ray eyeRay = new Ray(viveCameraEye.position, position);
Ray kneeRay = new Ray(viveCameraEye.position - Vector3.up * height * 0.75f, position);
RaycastHit eyeHit;
RaycastHit kneeHit;
if (!Physics.Raycast(eyeRay, out eyeHit, 1f))
{
if (!Physics.Raycast(kneeRay, out kneeHit, 1f))
transform.position += position * Time.deltaTime;
}
}
}