ContextActionService
用于键盘,鼠标和GamePad按钮相关的事件。但是,对于我的Steering,我想在控制器上使用操纵杆的位置。 我找到了多种找到鼠标位置的方法,我目前不想使用它们,但是无法直接获得游戏板操纵杆的位置。如果有办法,我找不到文档中关于它的评价。像pressingit一样,有按下它的down
,但没有任何位置 任何帮助将不胜感激。 如果您想获得操纵杆的位置,则需要使用ContextIonsEctionservice获取游戏板的输入对象。操纵杆的倾斜存储在对象的
Position
属性上。 the gamepad文档的演练非常好。
在当地的文章中尝试这样的东西:local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local gamepad = Enum.UserInputType.Gamepad1
if not UserInputService:GetGamepadConnected(gamepad) then
warn("No gamepad detected!")
return
end
local function handleInput(actionName : string, inputState : Enum.UserInputState, inputObject : InputObject)
if actionName == "MoveStick1" then
-- do something to handle the left joystick input
local moveVector : Vector3 = inputObject.Position
elseif actionName == "MoveStick2" then
-- do something to handle the right joystick input
local lookVector : Vector3 = inputObject.Position
end
end
ContextActionService:BindAction("MoveStick1", handleInput, false, Enum.KeyCode.Thumbstick1)
ContextActionService:BindAction("MoveStick2", handleInput, false, Enum.KeyCode.Thumbstick2)
为了更好地看到值,我将位置向量缩放100,将每个维度放入文本标签中。
在这个示例中...
左下角在右下象限中
正确的操纵杆大约在中间左右
the the the x和y轴上的操纵杆中的raw输入范围从[-1,1]。我不知道为什么这些值被包装到vector3而不是vector2中。
您还可以使用
userInputService.InputChanged