What should i multiply with delta?

Godot Version

4.2

Question

I want a character to move by controlling his jetpack. I ded this and the code worked fine on my laptop, but when i uploaded it to my phone it was going too fast. then, when i turned battery saving mode on, on my phone, whitch decreases the framerate, the character was too slow. I’ve been trying to multiply the final velocity with delta (and with 62 so then the speed isnt much different), but that doesnt seem to work because when i turn battery saving mode on, it goes faster than without battery saving mode.Can someone tell me what should i multiply with delta ? this is the code:

extends CharacterBody2D

const TYPE = "leo"
var gravity = 100
var rightjet = 0
var leftjet = 0
var horright = 0
var horleft = 0
var dontgoagain = false
var locleorot = global.leorot
var locleowind = global.leowind
var bumped = false
var sidebumped = false

func _process(delta):
	
	playfiresfx()
	playrfiresfx()
	
	if Input.is_action_pressed("leoright"):
		
		dontgoagain = false
		
		leftjet = move_toward(leftjet, 500, 5 )
		rightjet = move_toward(rightjet, 350, 3.2 )
		$RightLeoFire.visible = true
		$RightLeoFire.play("rightfire")
	else:
		$RightLeoFire.visible = false
	if Input.is_action_pressed("leoleft"):
		
		dontgoagain = false
		
		rightjet = move_toward(rightjet, 500, 5 )
		leftjet = move_toward(leftjet, 350, 3.2 )
		$LeftLeoFire.visible = true
		$LeftLeoFire.play("leftfire")
	else:
		$LeftLeoFire.visible = false
	if not Input.is_action_pressed("leoleft") and not Input.is_action_pressed("leoright"):
		if not is_on_ceiling() :
			leftjet = leftjet * 0.97
			rightjet = rightjet * 0.97
		else:
			if dontgoagain == false:
				horleft =  leftjet
				horright = rightjet 
				leftjet = 0
				rightjet = 0
				dontgoagain = true
		gravity = move_toward(gravity, 400, 3.5 )
	else:
		gravity = 100
	
	horright = horright * 0.95
	horleft = horleft  * 0.95
	
	locleorot = global.leorot
	locleowind = global.leowind
	
	if locleorot == 0:
		velocity = Vector2((((rightjet + horright) - (leftjet + horleft)) +locleowind), (0 - abs((rightjet - leftjet) - rightjet)) + gravity )#this is where i was trying to multiply with delta
		rotation = ((rightjet + horright) - (leftjet + horleft)) * 0.003 
	if locleorot == 90:
		velocity = Vector2( ((0 - abs((rightjet - leftjet) - rightjet)) + gravity) * -1 +locleowind, ((rightjet + horright) - (leftjet + horleft)))
		rotation = (((rightjet + horright) - (leftjet + horleft)) * 0.003) +1.55
	if locleorot == 180:
		velocity = Vector2(((rightjet + horright) - (leftjet + horleft))*-1 +locleowind, ((0 - abs((rightjet - leftjet) - rightjet)) + gravity)*-1)
		rotation = (((rightjet + horright) - (leftjet + horleft)) * 0.003) +3.125
	if locleorot == 270:
		velocity = Vector2( ((0 - abs((rightjet - leftjet) - rightjet)) + gravity) +locleowind, ((rightjet + horright) - (leftjet + horleft))*-1)
		rotation = (((rightjet + horright) - (leftjet + horleft)) * 0.003) +4.7
		
	
	
	$bumpsfx.volume_db = abs(velocity.y) / 10 - 45
	
	if is_on_ceiling() or is_on_floor():
		if not bumped:
			$bumpsfx.play()
			bumped = true
	else:
		bumped = false
	
	if is_on_wall():
		if not sidebumped:
			$bumpsfx.volume_db += -4
			$bumpsfx.play()
			sidebumped = true
	else:
		sidebumped = false
	
	move_and_slide()

func playfiresfx():
	if Input.is_action_just_pressed("leoleft"):
		$jetpacksfx/start.play()
		await get_tree().create_timer(0.5).timeout
		$jetpacksfx/loop.play()
	if Input.is_action_just_released("leoleft"):
		$jetpacksfx/finish.play()
		$jetpacksfx/loop.stop()
	if not Input.is_action_pressed("leoleft") and not Input.is_action_pressed("leoright"):
		$jetpacksfx/loop.stop()
		$jetpacksfx/start.stop()

func playrfiresfx():
	if Input.is_action_just_pressed("leoright"):
		$jetpacksfx/start.play()
		await get_tree().create_timer(0.5).timeout
		$jetpacksfx/loop.play()
	if Input.is_action_just_released("leoright"):
		$jetpacksfx/finish.play()
		$jetpacksfx/loop.stop()
	if not Input.is_action_pressed("leoright") and not Input.is_action_pressed("leoleft"):
		$jetpacksfx/loop.stop()
		$jetpacksfx/start.stop()

func _on_hurtbox_body_entered(_body):
	$hitsfx.play()
	Engine.time_scale = 0.1
	await get_tree().create_timer(0.1).timeout
	Engine.time_scale = 1.0
	get_tree().reload_current_scene()

move_and_slide don’t require multiplying by delta, but all physics related code should be called from _physics_process callback.

so how can i fix this?

Replace that for _physics_process

1 Like

ok, ill try and update

it works! thank you so much, you dont know for how long I’ve been tryng to fix this.

Np, just mark the question as solved and have fun