#Camera buggy on mobile

1 messages · Page 1 of 1 (latest)

haughty oriole
#

You need to share your camera movement code.

strong mauve
#

extends CharacterBody3D

@onready var HeadCamera = $HeadCamera
@export var sensitivity = 0.05

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var can_move = false

func _ready():
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
# Input.MOUSE_MODE_CAPTURED hides cursor and centers it

func _input(event):
if event is InputEventScreenDrag:
# Touch drag controls for looking around
var delta = event.relative # Drag direction and distance
process_touch_input(delta)

if event is InputEventMouseMotion and can_move:
    # Mouse look
    rotate_y(deg_to_rad(-event.relative.x * sensitivity))
    HeadCamera.rotate_x(deg_to_rad(-event.relative.y * sensitivity))
    HeadCamera.rotation.x = clamp(HeadCamera.rotation.x, deg_to_rad(-90), deg_to_rad(45))

func process_touch_input(delta: Vector2):
if can_move:
# Convert touch input into camera rotation
rotate_y(deg_to_rad(-delta.x * sensitivity))
HeadCamera.rotate_x(deg_to_rad(-delta.y * sensitivity))
HeadCamera.rotation.x = clamp(HeadCamera.rotation.x, deg_to_rad(-90), deg_to_rad(45))

func _physics_process(delta):

# Get the input direction and handle the movement/deceleration.
var input_dir := Input.get_vector("left", "right", "up", "down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
    velocity.x = direction.x * SPEED
    velocity.z = direction.z * SPEED
else:
    velocity.x = move_toward(velocity.x, 0, SPEED)
    velocity.z = move_toward(velocity.z, 0, SPEED)
#

Handle additional rotation controls

var look_x_left := Input.get_action_strength("look_left")
var look_x_right := Input.get_action_strength("look_right")
var look_y_up := Input.get_action_strength("look_up")
var look_y_down := Input.get_action_strength("look_down")

var look_x := look_x_right - look_x_left
var look_y := look_y_down - look_y_up

# Handle horizontal rotation
if abs(look_x) > 0.1:
    rotate_y(-look_x * sensitivity)

# Handle vertical rotation
if abs(look_y) > 0.1:
    HeadCamera.rotate_x(look_y * sensitivity)
    HeadCamera.rotation.x = clamp(HeadCamera.rotation.x, deg_to_rad(-90), deg_to_rad(45))
#

This is part of the camera of the player code

haughty oriole
#

In Project>Settings try disabling both of these:

strong mauve
#

thanks

#

Ill try that

#

When I disable both, I cant play the game on tablet

strong mauve
#

I might have found the issue

#

When i press the movement buttons i can still swipe. I think it has to do somethign with that and also multitouch

strong mauve
#

I tested it and it glitches with multitouch

haughty oriole
#

You need to account for touch inputs as well as mouse inputs separately.

The problem atm is that you are doing touch screen inputs and those are also sending mouse inputs. So you have duplicates.

Either rely entiry on touch or mouse inputs. Or disable both of the options above and make sure each case has conditions for handling both.

strong mauve
#

what is the best way to approach this? I want the game to run with keyboard mouse, controller and phone/tablet