i have the oculus rift player prefab in my scene. when i move around in real life in front of the sensor, the camera moves but the player holds the same position. so when i walk into a wall in game, i can move through the wall. how can i keep the camera in the player body?
VR cameras have a local offset applied by the VR system. This means that as you move around in room scale (or even around in front of a single sensor) your camera will be allowed to move outside of the character controller.
Additionally, Iâd recommend not bothering with a CharacterController at all if youâre doing a room scale experience. CharacterController is intended for when you want to forcibly move a character in a scene, but with room scale you want the playerâs position in their play space to dictate their position (relative some point in the scene to account for moving through larger scenes).
The best strategies Iâve heard of to deal with walking through walls tend to be things like applying some kind of effect to the camera so the user still perceives motion when clipping through walls but isnât able to see level geometry outside that they shouldnât. I donât have any examples off hand, but itâs definitely one of those tricky problems with room scale VR.
thanks for your reply. im using roomscale and a controller to move around. but i think it wil be a seated expirience from now on. the only head tracking used will be when your move your head left, right, up and down.
I was having this problem recently and couldnât find any proper solution at all then generated my own solution. Here Im gonna detail it. Firstly my main problem was when player moved in real life then move over controller since its center collision is at different place it was stucking collision it shouldnât be such that when player tries to move just near table collider stucks at table but playerâs front looks like free to move.
My Solution:
Firstly I generated a script that carries collider to Center Eye Anchorâs X and Z axises. Such that whenever player moves collider comes with it. It was okay for my problem but then I figured out this leads another big bug. It blocks us to bend over tables etc. it also blocks to goes inside walls which is okay but preventing us bending over objects is not good at all. So I generated another script which closes my first script at collider enter and placed this script over objects that I wanted to bend and when I exit trigger it is opening script back such that I can bend over everything that I want and also I donât stuck anywhere. It works well so far. If you get any bug over this let me know. Also here my scripts:
Script for collision problem
/*
This code is generated by Sasete. reach me over here, SaseteS@icloud.com
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VRCameraCharacterControllerFix : MonoBehaviour {
public CharacterController character;
public GameObject centerEyeAnchor;
private Vector3 place;
void FixedUpdate()
{
place = new Vector3(centerEyeAnchor.transform.localPosition.x, 0, centerEyeAnchor.transform.localPosition.z);
character.center = place;
}
}
Script for closing first script
/*
This code is generated by Sasete. reach me over here, SaseteS@icloud.com
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VRCameraCollisionFix : MonoBehaviour {
public GameObject OVRCameraRig;
private VRCameraCharacterControllerFix VRCameraCharacterControllerFix;
private void Start()
{
VRCameraCharacterControllerFix = OVRCameraRig.GetComponent<VRCameraCharacterControllerFix>();
}
private void OnTriggerEnter(Collider other)
{
if(TriggerVRObject(other))
VRCameraCharacterControllerFix.enabled = false;
}
private void OnTriggerExit(Collider other)
{
if (TriggerVRObject(other))
VRCameraCharacterControllerFix.enabled = true;
}
private bool TriggerVRObject(Collider other)
{
if (other.gameObject == OVRCameraRig)
return true;
else
return false;
}
}
Hey did this work?
Cause when I tried this the collider was not moving perfectly with the camera.It was not like not moving at all.
It was moving perfectly when I was looking forward but when I looked back the collider was far away from the camera so ,Player was unable to move.
Hi There,
I solved this problem by using buit in prefeb which is in the scene called âLocomotionâ and its path is âAssets\Oculus\SampleFramework\Usageâ and prefeb name is âPlayerControllerâ.
This is how you use scripts, only first code is for OVRCameraRig it simply teleports OVR camera rig to the Center Eye Anchorâs position continously.
And there is Wooden Platform that we have to bend over. To be able to do that, you have to enter this script over that, this script is just disable first script on trigger enter and when trigger exits re enable it
Yes, the CharacterCameraConstraint.cs script from the example scene Locomotion (Oculus Integration) solves the problem as @WR-reddevil suggested. I recommend adding that anyways, it also gives you the correct height for the player.
I tried this as of September 2020, and it no longer seems to work. In fact, building the original sample doesnât work either⌠no collision checking when moving in room scale seems to take place at all.
Hi All, I am also getting the same problem. I have added the CharacterCameraConstraint script to my PlayerController but still I am getting same problem.
Can anyone please help me to resolve this problem?
Dude, I canât thank you enough. Iâve been struggling with it for 2 years in my project. THANKS!!! I feel like celebrating now! haha I would hug you if I was close!