Welcome to the forums @rafatparvez!
To make a joystick work in a FPS, you will need to use the Vector2 returned by the joystick like the Vector2 recieved from the mouse position. However, because the touchscreen joystick is not an input event, and does not provide signals, you will need to process joystick input either in _process
or _physics_process
.
From a code point of view, it is more or less exactly what you are already doing, you just need to use the value returned by the get_value
function from the joystick in the code.
For example, adding the following to _process
should make the joystick rotate the camera:
var joystick_vector = joystick.get_value()
if joystick_vector != Vector2.ZERO:
# You’ll probably need to make a new sensitivity variable for the
# joystick. For this example, I’m just using mouse_sensitivity.
$Head.rotate_y(deg2rad(-joystick_vector.x * mouse_sensitivity))
var change = -joystick_vector.y * mouse_sensitivity
if change + camera_angle < 90 and change + camera_angle > -90:
$Head/Camera.rotate_x(deg2rad(change))
camera_angle += change