Godot Version
4.2.2
Question
I have a move_and_slide
script for moving a CharacterBody2D
. I recently noticed that on a different monitor with a different resolution the movement is much faster. (The base monitor where I code and test is 3440x1440. Then I tried on a 1920x1080). I did notice the delta
value is different - probably due to fps difference?
The movement script is trying to work off of swiping on a touch screen.
I tried removing the delta
variable, I tried using _physics_process
and also tried to implement a resolution check, after which I change the absolute values in the movement script based on the relative difference between the two screen resolutions. But the issue presists.
I’m quite new to this, so it might be something quite simple - but I ran out of ideas.
Any thoughts?
Code:
extends CharacterBody2D
# Variables to set up movement
var lenght := 5 # absolute value !
var StartPos: Vector2
var CurPos: Vector2
var swiping := false
var threshold := 10 # absolute value !
var direction: Vector2
var move_amount := 100 # absolute value !
func _process(delta):
# Movement script
if Input.is_action_pressed("ScreenTap"):
if !swiping:
swiping = true
StartPos = get_global_mouse_position()
if Input.is_action_pressed("ScreenTap"):
if swiping:
CurPos = get_global_mouse_position()
if StartPos.distance_to(CurPos) >= lenght:
if abs(StartPos.y - CurPos.y) >= threshold:
if StartPos.y > CurPos.y: #downward
direction = Vector2(0,-move_amount)
velocity = direction * Global.speed * delta
move_and_slide()
if StartPos.y < CurPos.y: #upward
direction = Vector2(0,move_amount)
velocity = direction * Global.speed * delta
move_and_slide()
swiping = false
if abs(StartPos.x - CurPos.x) >= threshold:
if StartPos.x > CurPos.x: #leftward
direction = Vector2(-move_amount,0)
velocity = direction * Global.speed * delta
move_and_slide()
if StartPos.x < CurPos.x: #rightward
direction = Vector2(move_amount,0)
velocity = direction * Global.speed * delta
move_and_slide()
swiping = false
else:
swiping = false