Hey there, I’m trying to essentially have a disc/ring appear to be centered in front of a hitPoint. The hitpoint location is determined by a raycast from the right controller of a VR headset. To center it in front of the playerCamera I am casting a ray from the playerCamera to the hitPoint. I’ve tried a number of different methods for this, and they all mostly work except for one thing: when I tilt my head sideways, the ring always looks to shift up/down relative to the hitPoint. If I pause it and edit the Z-Axis rotation of the ring it seems to recenter it, but of course then it’s off center when I’m not tilted.
I’m assuming this has something to do with the peculiarities of complex rotations and what’s considered ‘up’ and ‘forward’ in Unity, but it’s above my understanding. Has anyone done this before? Pasting one approach to this part of the code below. Thanks!
if (Physics.Raycast(rightHand.position, rightHand.forward, out hit, maxDistance, layerMask))
{
if (isAnimating == false)
{
hitPoint = hit.point;
CameraParent.position = hitPoint;
// Calculate the direction from the camera to the hitpoint to position mask objects
Vector3 direction = hitPoint - playerCamera.position;
Vector3 directionR = hitPoint - playerCameraR.position;
Vector3 camToHit = hitPoint - playerCamera.position;
Vector3 objectPos = playerCamera.position + camToHit.normalized * distance;
discParentL.position = objectPos;
discParentL.LookAt(hitPoint);
}
}