Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make this script controller-compatible?

Asked by
sprcrz 0
3 years ago

Hello. I have a script that enables flight mode in my game. I took the bulk of the script from another helpful post and modified it to fit my needs. It works on PC but when I activate flight mode using a controller, the character doesn't move at all. I can still rotate the camera around the character, but I cannot move the character. It seems to me that the culprit is in this part of the script, but I cannot figure out how to fix it. Would anyone be able to help me?

local function movementBind(actionName, inputState, inputObject)
    if (inputState == Enum.UserInputState.Begin) then
        movement[actionName] = 1;
    elseif (inputState == Enum.UserInputState.End) then
        movement[actionName] = 0;
    end
    if (isFlying) then
        local isMoving = movement.right + movement.left + movement.forward + movement.backward > 0;
    return Enum.ContextActionResult.Pass;
end

game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterForward);
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackward);
game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft);
game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight);

Answer this question