Set characters head at a specific location in the world space

Hi guys,

I am developing a listening experiment where I need 3 degrees of freedom and I need the character’s head to be set at a specific location in the world space but I am struggling because it is a child in the XR Origins hierarchy.

Have tried the following script but it doesn’t set the head at the correct height. (It seems that I am placed higher than expected) and even if I change the height it positions the main camera at the same spot.

Also my controllers are not following the body at all. Why? Is it because of the 3 DoF?

Could you please give a hand?

Thanks!!

EleniT

using UnityEngine;

public class SetHeadPosition : MonoBehaviour
{
public Transform xrOrigin; // Reference to the XR Origin (root of the hierarchy)
public Transform cameraOffset; // Reference to the Camera Offset
public Transform mainCamera; // Reference to the Main Camera (head)

// Desired world position for the character's head (Main Camera)
public Vector3 targetHeadPosition = new Vector3(0, 1.6f, 0);

void Start()
{
    // Adjust the camera offset so that the Main Camera is positioned at the target position in world space
    AdjustCameraOffset();
}

void AdjustCameraOffset()
{
    // Get the current world position of the Main Camera
    Vector3 currentHeadPosition = mainCamera.position;

    // Calculate the difference between the current head position and the desired target position
    Vector3 positionDifference = targetHeadPosition - currentHeadPosition;

    // Apply this difference to the Camera Offset's position to adjust the Main Camera's position
    cameraOffset.position += positionDifference;
}

}