please help me fix a bug in my game

I have a game that has button control for now, oh yeah, it’s a 3D game, there’s camera control. This game is for mobile devices. What’s the bug? When you press the walk button, the camera mechanics don’t work. It’s done by tracking the cursor (mobile devices use cursor emulators). My guess is that when you press the button, the cursor moves to the button, thereby preventing you from rotating the camera with 2 fingers. Here are two codes that are involved:

code for camera
extends Node3D

var v = Vector3()

func _ready():
pass

func _input(event):
if event is InputEventMouseMotion:
if event.position.x > 1000:
v.y -= (event.relative.x * 0.2)
v.x -= (event.relative.y * 0.2)
v.x = clamp(v.x,-80,90)
func _physics_process(_delta):
$main.rotation_degrees.x = v.x
$“…/…”.rotation_degrees.y = v.y

code for movement
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5

func _ready() → void:
set_process_input(true)

func _physics_process(delta: float) → void:

Add the gravity.

if not is_on_floor():
velocity += get_gravity() * delta

Handle jump.

if Input.is_action_just_pressed(“ui_accept”) and is_on_floor():
velocity.y = JUMP_VELOCITY

Get the input direction and handle the movement/deceleration.

As good practice, you should replace UI actions with custom gameplay actions.

var input_dir := Input.get_vector(“left”, “right”, “run”, “back”)
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)

move_and_slide()

I would be very grateful to anyone who could help fix this bug.

Please format the code using the preformatted text with ```
Also, please record a short video or a screenshot showing the issue.

1 Like