Hello, I’m trying to implement a script that restricts player movement, specifically for the XR Origin. I’d like to set up boundaries along the x and y axes. Currently testing for x axis. This is what I have:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBoundary : MonoBehaviour
{
// boundary limit on x (-1, 1)
// boundary limit on z (-4,6) - optional
private float limitX = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.x > limitX)
{
Debug.Log("Player is restricted");
transform.position = new Vector3(limitX, transform.position.y, transform.position.z);
}
if (transform.position.x < -limitX)
{
Debug.Log("Player is restricted");
transform.position = new Vector3(-limitX, transform.position.y, transform.position.z);
}
}
}
Another approach is to retrieve locmotion game object and disable / dynamic move provided?