嗨,我们(我和我的学生)正在使用MRTK在团结,以建立简单的虚拟现实游戏。
我们正在尝试让xBox控制器移动播放器(或者用MRTK术语来说,我认为可以在摄像机周围移动场景,它的固定值为0,0,0)。
我已经设置了控制器,并使用了MRTK设置,但没有运气。
我的控制器在Windows混合现实门户中工作得很好,但当游戏加载时就会死掉。
任何有关MRTK编辑器窗口中的具体步骤/设置的帮助都是非常感谢的。
本
发布于 2019-08-14 23:02:22
这里有两件事需要解决:
MixedRealityPlayspace.Transform.Translate您可以使用以下代码使用游戏垫移动MR Playspace:
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine;
/// <summary>
/// Moves the player around the world using the gamepad, or any other input action that supports 2D axis.
///
/// We extend InputSystemGlobalHandlerListener because we always want to listen for the gamepad joystick position
/// We implement InputHandler<Vector2> interface in order to receive the 2D navigation action events.
/// </summary>
public class MRPlayspaceMover : InputSystemGlobalHandlerListener, IMixedRealityInputHandler<Vector2>
{
public MixedRealityInputAction navigationAction;
public float multiplier = 5f;
private Vector3 delta = Vector3.zero;
public void OnInputChanged(InputEventData<Vector2> eventData)
{
float horiz = eventData.InputData.x;
float vert = eventData.InputData.y;
if (eventData.MixedRealityInputAction == navigationAction)
{
delta = CameraCache.Main.transform.TransformDirection(new Vector3(horiz, 0, vert) * multiplier);
}
}
public void Update()
{
if (delta.sqrMagnitude > 0.01f)
{
MixedRealityPlayspace.Transform.Translate(delta);
}
}
protected override void RegisterHandlers()
{
CoreServices.InputSystem.RegisterHandler<MRPlayspaceMover>(this);
}
protected override void UnregisterHandlers()
{
CoreServices.InputSystem.UnregisterHandler<MRPlayspaceMover>(this);
}
}我使用以下控制器映射将dpad和拇指棒挂钩到导航操作:

然后我创建了一个新的游戏对象,附加了MRPlayspaceMover脚本,并分配了“导航操作”字段:

https://stackoverflow.com/questions/57469979
复制相似问题