Solve the problem of inaccurate movement when the CameraRig position is forced to move instantaneously (VRTK)

Instantaneous movement in Unity SteamVR is generally achieved by setting the position of the CameraRig. In the case of low accuracy requirements, it will not be too difficult to directly set its position. However, in some occasions with high precision requirements, sometimes the forced setting of its position will lead to mold piercing, camera entering other objects, etc.

reason

The center point of CameraRig is the center point set in the SteamVR room settings. After the player wears the helmet, if the place where he stands is not the center position set previously, his eye camera and body collision box will be offset according to the real position.

When we force the position of the CameraRig to move, because the player has a certain offset from the center point of the CameraRig, the player may enter other models and cause threading.

To sum up, the reason: Although the CameraRig has moved to the place you want, the player's body below it is not in the center of the CameraRig.

resolvent

The solution is simple. The purpose of blink is to move the player's body represented by Camera (Eye) to the target position, so Calculate the offset between the player's body and CameraRig , calculate the correct position of the CameraRig that needs to be moved instantaneously according to the offset.

 //Extracted from VRTK_BasicTeleport script of development version protected virtual Vector3 GetCompensatedPosition(Vector3 givenPosition,  Vector3 defaultPosition) { float newX = 0f; float newY = 0f; float newZ = 0f; if (ValidRigObjects()) { newX = (headsetPositionCompensation ?  (givenPosition.x - (headset.position.x - playArea.position.x)) : givenPosition.x); newY = defaultPosition.y; newZ = (headsetPositionCompensation ?  (givenPosition.z - (headset.position.z - playArea.position.z)) : givenPosition.z); } return new Vector3(newX, newY, newZ); }

VRTK out of the box approach

If you think your own calculation is too troublesome, consider the VRTK plug-in developed on Github. stay New VRTK The basic transfer script VRTK_BasicTeleport has been encapsulated for users Accurate blink method that can be called by code The precise blink method is realized by the principle mentioned above.
Script name: VRTK_BasicTeleport (only for development version, see VRTK github warehouse)

 //Transfer (including processing of offset) //Parameters: target: destination object (mark, useless in blink), destinationPosition: blink world coordinate, destinationRotation: rotation, forceDestinationPosition: blink whether the target point changes public virtual void Teleport(Transform target,  Vector3 destinationPosition, Quaternion? destinationRotation = null, bool forceDestinationPosition = false) //Forced transfer (including processing of offset), ignoring collision, obstruction, floor, etc //Parameters: destinationPosition: world coordinate point to be moved, destinationRotation: rotation to be performed teleporter.ForceTeleport(Vector3 destinationPosition,  Quaternion? destinationRotation = null);

References

1. [Header] [Unity] Unity Japan UnityChanSD Role

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/4107.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*

Comment area

  1. littleplus 08-28 13:21 reply

    There are many articles written by Rabbit Unity. Is this work demand?

    • hare 08-28 21:57 reply

      I can't help it. I can't do anything else. I can only write this pretend look.

  2. LingC 08-29 17:26 reply

    This is cool

  3. mikusa 08-29 21:01 reply

    Next, it's time to write cut pictures!