Hi Guys,
I’m trying to make a character fly using input controls. So far so good with the keyboard input (WASD and arrows), but XBOX controller thumbstick and mobile touch are not working at this point.
I’m getting close using XBOX controller input, but somehow I’m missing something. When I enter the seat and use the Thumbstick1 position, forward and backward are working, but the camera position shows sideways.
I used this piece of code to get the Vector3 position right:
userInputService.InputChanged:connect(function(inputObject, gameProcessedEvent)
if gameProcessedEvent then
--print("A button is being pressed on a gamepad! Button:",inputObject.KeyCode)
if inputObject.KeyCode == Enum.KeyCode.Thumbstick1 then
--print("The thumbstick button has been pressed at",inputObject.Position)
local position = inputObject.Position
-- If the stick goes 10% past the center, activate
if position.Magnitude > 0.1 then
local Xv
local Yv
local Zv
if position.X > 0 then
Xv = 1
elseif position.X < 0 then
Xv = -1
end
if position.Y > 0 then
Yv = 1
elseif position.Y < 0 then
Yv = -1
end
if position.Z > 0 then
Zv = 1
elseif position.Z < 0 then
Zv = -1
end
movement = Vector3.new(Xv,Yv,Zv)
print(movement)
end
end
end
end)
When trying to go forward with the Thumbstick forward, the character moves sideways (I guess because of the camera position):
The lookvector isn’t right as well, strangely enough it does seem to be correct on the keyboard inputs (as the left and right arrow steers the camera, not the character). But when I start using the Thumbstick1 the camera changes sideways
If I use the Thumbstick2 I’m able to steer the character left and right, but still the lookvector isn’t right.
Any idea how to setup the script to use the Thumbstick to move (and look) in the correct direction? Any help is being appreciated!