unity3d+VRTK:强制传送,主动传送到场景中预设的点(位置与摄像机角度)

2023-08-24 14:49:47 浏览数 (1)

不用射线触发,主动传送到场景中预设的点 新版本的强制传送

代码语言:javascript复制
        public virtual void ForceTeleport(Vector3 destinationPosition, Quaternion? destinationRotation = null)
        {
            DestinationMarkerEventArgs teleportArgs = BuildTeleportArgs(null, destinationPosition, destinationRotation);
            StartTeleport(this, teleportArgs);
            Quaternion updatedRotation = SetNewRotation(destinationRotation);
            Vector3 finalDestination = GetCompensatedPosition(destinationPosition, destinationPosition);
            CalculateBlinkDelay(blinkTransitionSpeed, finalDestination);
            Blink(blinkTransitionSpeed);
            if (ValidRigObjects())
            {
                playArea.position = finalDestination;
            }
            ProcessOrientation(this, teleportArgs, finalDestination, updatedRotation);
            EndTeleport(this, teleportArgs);
        }

老版本的强制传送

代码语言:javascript复制
        public virtual void ForceTeleport(Vector3 destinationPosition, Quaternion? destinationRotation = null)
        {
            DestinationMarkerEventArgs teleportArgs = BuildTeleportArgs(null, destinationPosition, destinationRotation);
            StartTeleport(this, teleportArgs);
            CalculateBlinkDelay(blinkTransitionSpeed, destinationPosition);
            Blink(blinkTransitionSpeed);
            if (ValidRigObjects())
            {
                playArea.position = destinationPosition;
            }
            Quaternion updatedRotation = SetNewRotation(destinationRotation);
            ProcessOrientation(this, teleportArgs, destinationPosition, updatedRotation);
            EndTeleport(this, teleportArgs);
        }

后设置camerarig角度,导致每次传送的位置有偏差,所以更新下vrtk版本,解决这个问题。

如果在强制传送的,想同时调整相机的角度,即 同时调整传送后相机角度与位置

代码语言:javascript复制
    public void Teleport(Transform trans)
    {
        Quaternion tempQ = Quaternion.Euler(trans.eulerAngles); 
        m_teleport.ForceTeleport(trans.position, GetRotation(trans));
    }

    Quaternion GetRotation(Transform trans)
    {
        float offset = ( m_playArea != null && m_headset != null ? m_playArea.eulerAngles.y - m_headset.eulerAngles.y : 0f);
        return Quaternion.Euler(0f, trans.eulerAngles.y   offset, 0f);
    }

m_headset 为camera(eye) m_playArea为cemerarig 计算传送后应该补偿的夹角得到新的rig方向

传送后即为箭头预设方向

0 人点赞