If you’re using Opsive’s UFPS (Ultimate FPS) in Unity with a VR headset such as an Oculus Rift, you can add this script to the UFPS player to automatically rotate the player in the direction that the headset it looking.

 

VRLookToMoveUFPS.cs:

using UnityEngine;
using System.Collections;

/// <summary>
/// If using a VR device, rotate the UFPS player in the direction that the camera 
/// is looking when the player moves.
/// </summary>
public class VRLookToMoveUFPS : MonoBehaviour
{

	public float movementThreshold = 0.1f;
	
	private vp_FPCamera m_fpCamera;
	private vp_FPPlayerEventHandler m_fpPlayer;

	private IEnumerator Start()
	{
		yield return null; // Give UFPS one frame to set up.
		m_fpPlayer = FindObjectOfType<vp_FPPlayerEventHandler>();
		m_fpCamera = m_fpPlayer.GetComponentInChildren<vp_FPCamera>();
		enabled = UnityEngine.VR.VRSettings.enabled && (UnityEngine.VR.VRSettings.loadedDevice != UnityEngine.VR.VRDeviceType.None) && 
			(m_fpPlayer != null) && (m_fpCamera != null);
	}

	private void Update()
	{
		if (m_fpPlayer.Velocity.Get().magnitude > movementThreshold)
		{
			m_fpPlayer.Rotation.Set(new Vector2(m_fpPlayer.transform.rotation.eulerAngles.x, m_fpCamera.transform.rotation.eulerAngles.y));
			UnityEngine.VR.InputTracking.Recenter();
		}
	}
	
}