我正在使用 oculus 集成工具包。我能夠將運動系結到我的 oculus quest 2 控制器的拇指桿上。如果我向右推動搖桿,我會向右移動;如果我向左推,我會向左移動。然而,移動發生在每次推動時,它不是連續的。我希望在我仍然向右或向左推動拇指桿時繼續移動。請問我該怎么做。
這是我的代碼。
void Update()
{
if (OVRInput.GetUp(OVRInput.Button.PrimaryThumbstickRight))
{
gameObject.transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.World);
}
if (OVRInput.GetUp(OVRInput.Button.PrimaryThumbstickLeft))
{
gameObject.transform.Translate(Vector3.back * speed * Time.deltaTime, Space.World);
}
}
uj5u.com熱心網友回復:
當按鈕被釋放時,OVRInput.GetUp 回傳 true。看起來你是在問他們什么時候停止按下拇指桿。
我建議使用這樣的代碼:
// this gets the X and Y values of the thumbstick
vector2 input = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
// this moves the character based on how much the x axis is pressed.
// it's the same as your code, but it multiplies by the x axis instead
// of using a condition. doing this means you can also only partially
// push the joystick and you will only partially move.
gameObject.transform.Translate(Vector3.forward * speed * input.x * Time.deltaTime, Space.World);
如果您不希望他們能夠部分按下它以部分移動,您可以使用您的原始代碼,但在條件中使用input.x > 0.75f和input.x < -0.75f代替。
我通過快速谷歌搜索在這里找到了這一切。在你提問之前,盡量確保谷歌還不知道答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/533589.html
標籤:C#unity3d元宇宙
上一篇:如何立即跳過/完成協程?
