holopy3/Assets/Scripts/UprightWalk.cs

23 lines
985 B
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UprightWalk : MonoBehaviour
{
public Camera VRCam;
public LayerMask Ground;
private RaycastHit hit;
private void Update()
{
//Get RaycastHit on the ground beneath the camera
Physics.Raycast(VRCam.transform.position, Vector3.down, out hit, Mathf.Infinity, Ground/*, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal*/);
// Translate playerbody with the camera by adapting it to this hitpoint as well as adjusting the height
transform.position = new Vector3(hit.point.x, VRCam.transform.position.y - Vector3.Distance(VRCam.transform.position, hit.point) / 2, hit.point.z);
// Resize the body depending of the height of the camera
transform.localScale = new Vector3(transform.localScale.x, Vector3.Distance(VRCam.transform.position, hit.point)/2, transform.localScale.z);
}
}