My dash function force changes when higher and lower than 60 fps

Godot Version

4.4.1.stable

Question

I see the problem when dashing upwards. The dash function uses a tween to do it’s function, and I think it has to do with this problem, because as I stop using dodge power the dash doesn’t change how high it goes when the fps changes.

Here is the dash velocity code:

			velocity.x = direction * (SPEED + dodgepower) * 1.4 ## direction = left and right input.
			velocity.y = directionyaxis * (dodgepower) * 1.6 ## directionyaxis = up and down input, dodgepower = the power that's being tweened.

Here is the dodge power code:

dodgepower = dodge ##dodge = 1600 
		if tween:
			tween.stop()
		tween = create_tween()
		
		tween.tween_property(self, "dodgepower", 0, 0.18).set_ease(Tween.EASE_OUT)
		move_and_slide()

Any help would be appreciated!

Is that code in _process() or _physics_process()?

I made my dash function inside a custom function not inside physics process, is they’re a way to make it into a custom function?

I cut the dodge function’s code and put it in the _physics_process() function and it still has the problem.

You’d have to show more of your code, maybe the entire script. If this sample isn’t inside _physics_process then you have a strange out of place call to move_and_slide().

I see you’re using dodgepower to control the velocity, and the dodgepower is reduced by a tween. I suspect the stray move_and_slide() may be the culprit, making your player move more than once per frame.

I’m with @gertkeno. We need to see the whole script to help you. Otherwise we are going to be playing 20 questions.

Ok, Here the whole script:

extends CharacterBody2D

var SPEED = 480.0
var JUMP_VELOCITY = -680.0
var ah = 0
var walk = false
var canDodge = true
var waitDodge = false
var isDodge = false
var dodge
var tween: Tween
var dodgepower = 0.0
var slow = 1
var closetoground = false
var savejump = false
var forcecrawl = false
var willinglycrawl = false
var dontslide = false
var ingorewill = false
var wallclimbmode = false
var tired = false
var prevVelocity: Vector2 = Vector2.ZERO
var climbpower = 200
var left = false
var right = false
var direction
var constant = false
var directionyaxis
var fallfaster = false
var dead = false
var wallgrabstop = false
var lastdirectionx = 0
var lastdirectiony = 0
var cantjump = false
var movementvector
var controller = false
var bounce = false
var canbounce = false
var didbounce = false
var bouncenum = 0
var guything = false
var canwallbounce = false
var lastwalljump = false
var stopdashvelo = false
var ducking = false
var duckloop = false
var alreadyreleasedjump = false
var nuhuh = false
var downwardslash = false
var cutitout = false
var hitbounce = false
var stillslash = false
var horizontalslash = false
var alreadyreleasedslash = false
var lookup = false
var lookuploop = false
var grabbing = false
var out = false
var aaaaaa = false

var noJumping = false
var moving = false
var movingup = false
var movingdown = false
var dashrandom
var chirprandom
var rng = RandomNumberGenerator.new()
@onready var climbingup : AudioStream = preload("res://audio/groundsounds/climbingrock.wav")
@onready var climbingdown : AudioStream = preload("res://audio/groundsounds/scraperock.wav")
@onready var normchirp1 : AudioStream = preload("res://audio/birdchirps/01-1.wav")
@onready var normchirp2 : AudioStream = preload("res://audio/birdchirps/02-2.wav")
@onready var normchirp3 : AudioStream = preload("res://audio/birdchirps/03-3.wav")
@onready var normchirp4 : AudioStream = preload("res://audio/birdchirps/04-4.wav")
@onready var normchirp5 : AudioStream = preload("res://audio/birdchirps/05-5.wav")
@onready var normchirp6 : AudioStream = preload("res://audio/birdchirps/06-6.wav")
@onready var rock : AudioStream = preload("res://audio/groundsounds/running on gravel.wav")
@onready var wood : AudioStream = preload("res://audio/groundsounds/running on wood.wav")


var debug = false

func _ready() -> void:
	
	pass
func directions():
	
	if Input.is_action_just_released("Climb"):
		wallclimbmode = false

	direction = Input.get_axis("ui_left", "ui_right")

		
	directionyaxis = Input.get_axis("ui_up", "ui_down")

	
		
	lastdirectionx = direction
	lastdirectiony = directionyaxis

func _physics_process(delta: float) -> void:
	if Input.is_action_just_pressed("Reset") and Globals.reset == false and dead == false:
		Dead()
	if grabbing == true:
		wallclimbmode = false
	if Input.is_action_just_pressed("Debug") and debug == false:
		debug = true
	if Input.is_action_just_released("Debug") and debug == true:
		debug = false
	$GPUParticles2D2.emitting = false
	$GPUParticles2D3.emitting = false
	$GPUParticles2D4.emitting = false
	directions()
	if dead == false and debug == false:
		set_collision_mask_value(1, true)
		set_collision_mask_value(2, true)
		set_collision_mask_value(4, true)
		$AreaDangerDetection/CollisionShape2D.disabled = false
		
		
		if Input.is_action_just_pressed("ui_accept") and $Jump.playing == false and noJumping == false:
			noJumping = true
			$Jump.play()

			
		if direction and is_on_floor():
			moving = true
			if aaaaaa == false or isDodge == false and $WalkingSound.playing == false :
				$WalkingSound.play()
				aaaaaa = true
		if not direction or not is_on_floor():
			moving = false
			aaaaaa = false
			$WalkingSound.stop()
		
			
		if not wallclimbmode:
			$Climbing.stop()
		if directionyaxis < 0 and wallclimbmode == true and tired == false and $HoldRadius.alreadyholding == false:
			movingup = true
		elif directionyaxis > 0 and wallclimbmode == true or wallclimbmode == true and tired == true and $HoldRadius.alreadyholding == false:
			movingdown = true
		elif not directionyaxis or wallclimbmode == false and tired == false and $HoldRadius.alreadyholding == false:
			movingup = false
			movingdown = false
			$Climbing.stop()
		if tired == true and wallclimbmode == true and $HoldRadius.alreadyholding == false:
			movingup = false
			movingdown = true
		if movingup == true and $Climbing.playing == false and tired == false and $HoldRadius.alreadyholding == false:
			$Climbing.stream = climbingup
			$Climbing.play()
		elif movingdown == true and $Climbing.playing == false or $Climbing.playing == false and tired == true and $HoldRadius.alreadyholding == false:
			$Climbing.stream = climbingdown
			$Climbing.play()
			
		if Input.is_action_just_pressed("Chirp"):
			
			chirprandom = round(rng.randf_range(1,2))
			rng.randomize()
			if chirprandom == 1.0:
				if not Input.is_action_pressed("ui_down") and not Input.is_action_pressed("ui_up"):
					$Chirps.stream = normchirp1
				elif Input.is_action_pressed("ui_up") and not Input.is_action_pressed("ui_down"):
					$Chirps.stream = normchirp2
				elif not Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
					$Chirps.stream = normchirp3
				elif Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_up"):
					$Chirps.stream = normchirp1
				$Chirps.play()
					
			elif chirprandom == 2.0:
				if not Input.is_action_pressed("ui_down") and not Input.is_action_pressed("ui_up"):
					$Chirps.stream = normchirp4
				elif Input.is_action_pressed("ui_up") and not Input.is_action_pressed("ui_down"):
					$Chirps.stream = normchirp5
				elif not Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
					$Chirps.stream = normchirp6
				elif Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_up"):
					$Chirps.stream = normchirp1
				$Chirps.play()
					
				
		if Input.is_action_just_released("Chirp"):
			$Chirps.stop()
		if Input.is_action_just_pressed("ui_accept") and Input.is_action_just_pressed("Dodge"):
			canbounce = false
			bounce = false
			didbounce = false
		if direction < 0 and direction > -1:
			direction = -1
		elif direction > 0 and direction < 1:
			direction = 1
		if directionyaxis < 0 and directionyaxis > -1:
			directionyaxis = -1
		elif directionyaxis > 0 and directionyaxis < 1:
			directionyaxis = 1
		if wallgrabstop == true and $WallGrabStop.is_stopped():
			$WallGrabStop.start()
			wallclimbmode = false
		if is_on_floor():
			out = false
			canDodge = true
			$DodgeTimer.wait_time = 0.6
			noJumping = false
			didbounce = false
			fallfaster = false
			$WallTimer.stop()
			tired = false
			$CoyoteJump.stop()
			cantjump = false
			guything = false
			lastwalljump = false
			alreadyreleasedjump = false
			alreadyreleasedslash = false
			$FlickSound.stop()
			if Input.is_action_pressed("ui_down") and not direction and is_on_floor():
				ducking = true
			elif Input.is_action_just_released("ui_down") or direction or not is_on_floor():
				ducking = false
				duckloop = false
				$DuckDown.stop()
			elif Input.is_action_pressed("ui_up") and not direction and is_on_floor():
				lookup = true
			elif Input.is_action_just_released("ui_up") or direction or not is_on_floor():
				lookup = false
				lookuploop = false
				$DuckDown.stop()
			elif Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_up"):
				ducking = false
				duckloop = false
				lookup = false
				lookuploop = false
				$DuckDown.stop()
		if ducking == true and lookup == false and is_on_floor() and not direction:
			if duckloop == false:
				$AnimationPlayer.play("Duck")
			if $AnimationPlayer.current_animation == "Duck" and $DuckDown.is_stopped():
				$DuckDown.start()
		elif lookup == true and ducking == false and is_on_floor() and not direction:
			if lookuploop == false:
				$AnimationPlayer.play("Lookup")
			if $AnimationPlayer.current_animation == "Lookup" and $DuckDown.is_stopped():
				$DuckDown.start()
			
			
		if wallclimbmode == true and left == true and lastwalljump == false and grabbing == false and $HoldRadius.alreadyholding == false or wallclimbmode == true and right == true and lastwalljump == false and grabbing == false and $HoldRadius.alreadyholding == false:
			$WallTimer.paused = false
			$AnimationPlayer.speed_scale = 1
			$Wallbouncebefore.stop()
			$FlickSound.stop()
			noJumping = false
			didbounce = false
			bounce = false
			fallfaster = false
			constant = false
			if canwallbounce == true:
				$Wallbounce.stop()
				$Wallbounce.start()
			if $WallTimer.is_stopped():
				$WallTimer.start()
			if Input.is_action_pressed("ui_up") and tired == false:
				$AnimationPlayer.play("ClimbingUp")
				velocity.y = -climbpower
			elif Input.is_action_pressed("ui_down") and tired == false:
				$AnimationPlayer.play("ClimbingDown")
				velocity.y = climbpower
			elif tired == true:
				velocity += get_gravity() * delta / 4
				$AnimationPlayer.play("ClimbingDown")
				if Input.is_action_just_pressed("ui_accept") and wallclimbmode == true and $HoldRadius.alreadyholding == false:
					velocity.y += -500
					wallclimbmode = false
					wallgrabstop = true
			else:
				if tired == false:
					$AnimationPlayer.play("ClimbingIdle")
					velocity.y = 0
			pass
		if $WallTimer.get_time_left() < 2.1 and wallclimbmode == true and grabbing == false or tired == true:
			$GPUParticles2D2.emitting = true
			$GPUParticles2D3.emitting = true
			$GPUParticles2D4.emitting = true
		if is_on_floor() and not Input.is_action_just_pressed("Slide"):
			dodge = 1600.0
		else:
			dodge = 1600.0
		if not is_on_floor():
			$DodgeTimer.wait_time = 0.2
		if constant == false and is_on_floor():
			stopdashvelo = false
		if wallclimbmode == false:
			$AnimationPlayer.speed_scale = 0.5
		# Add the gravity.
		if not is_on_floor() and wallclimbmode == false and isDodge == false and Globals.falling == false:
			velocity.x = lerp(prevVelocity.x,velocity.x, 1.0)
			duckloop = false
			lookuploop = false
			velocity += get_gravity() * delta * 1.6
			
		if not is_on_floor() and wallclimbmode == false and isDodge == false and Globals.falling == true:
			velocity += get_gravity() * delta * 2.2
			duckloop = false
			lookuploop = false
		if not is_on_floor() and $CoyoteJump.is_stopped():
			$CoyoteJump.start()
		# Handle jump.
		if Input.is_action_just_pressed("ui_accept") and cantjump == false and wallclimbmode == false and isDodge == false:
			fallfaster = false
			cantjump = true
			canbounce = true
			constant = false
			isDodge = false
			ah = 1
			velocity.y = JUMP_VELOCITY
			savejump = false
		
		elif Input.is_action_just_pressed("ui_accept") and cantjump == false and wallclimbmode == false and isDodge == true and canbounce == true and is_on_floor() and velocity.x == 0:
			fallfaster = false
			cantjump = true
			constant = false
			isDodge = false
			ah = 1
			velocity.y = JUMP_VELOCITY -80 * 4.2
			bounce = true
			savejump = false
			didbounce = true
			
		elif Input.is_action_just_pressed("ui_accept") and cantjump == false and wallclimbmode == false and isDodge == true and canbounce == true and is_on_floor() and not velocity.x == 0:
			fallfaster = false
			cantjump = true
			constant = false
			isDodge = false
			ah = 1
			velocity.y = JUMP_VELOCITY -80 * 2.5
			velocity.x = direction * SPEED * 10
			bounce = true
			savejump = false
			didbounce = true

		elif Input.is_action_just_pressed("ui_accept") and savejump == false and closetoground == false and wallclimbmode == true and tired == false and left == true:
			fallfaster = false
			$WallGoneTimer.stop()
			cantjump = true
			leftwallgone()
			rightwallgone()
			constant = false
			isDodge = false
			wallclimbmode = false
			nuhuh = true
			velocity.y = JUMP_VELOCITY + 30
			##velocity.x += 2000
		elif Input.is_action_just_pressed("ui_accept") and savejump == false and closetoground == false and wallclimbmode == true and tired == false and right == true:
			fallfaster = false
			$WallGoneTimer.stop()
			cantjump = true
			leftwallgone()
			rightwallgone()
			constant = false
			isDodge = false
			wallclimbmode = false
			nuhuh = true
			velocity.y = JUMP_VELOCITY + 30
			##velocity.x += -2000
				
			##if canwallbounce == false and tired == false:
				##velocity.y = JUMP_VELOCITY + 50
			##elif canwallbounce == true and tired == false:
				##$Wallbouncebefore.stop()
				##$Wallbounce.stop()
				##velocity.y = JUMP_VELOCITY - 350
				##canwallbounce = false
			savejump = false
			canbounce = true
			
			
			

		
		if Input.is_action_just_released("ui_accept") and isDodge == false and alreadyreleasedjump == false:
			fallfaster = false
			constant = false
			velocity.y *= 0.4
			canbounce = true
			alreadyreleasedjump = true
		elif Input.is_action_just_released("Slash") and not is_on_floor() and alreadyreleasedslash == false and $HoldRadius.alreadyholding == false:
			fallfaster = false
			constant = false
			velocity.y *= 0.4
			canbounce = true
			alreadyreleasedslash = true


		if is_on_floor() and not Input.is_action_just_pressed("ui_accept"):
			ah = 0
		if velocity.y < 0 and wallclimbmode == false:
			savejump = false
			if isDodge == false and cutitout == false and dead == false and didbounce == false or isDodge == false and cutitout == false and dead == false and out == true:
				
				$AnimationPlayer.play("Jump")
			elif isDodge == false and cutitout == false and dead == false and didbounce == true and out == false:
				$AnimationPlayer.play("DoubleJump")
			Globals.slow = true
			Globals.run = false
			Globals.falling = false
			Globals.idle = false
		##elif velocity.y < 0 and didbounce == true:
			
			##if wallclimbmode == false and cutitout == false:
				##$AnimationPlayer.play("DoubleJump")
			##Globals.slow = true
			##Globals.run = false
			##Globals.falling = false
			##Globals.idle = false
		elif velocity.y > 0 and wallclimbmode == false:
			$WalkTimer.start()
			if isDodge == false and not is_on_floor() and cutitout == false and didbounce == false or isDodge == false and not is_on_floor() and cutitout == false and out == true:
				$AnimationPlayer.play("Fall")
			Globals.slow = false
			Globals.run = false
			Globals.falling = true
			Globals.idle = false
			
		if is_on_floor() and Input.is_action_just_pressed("Dodge"):
			canbounce = false
		# Get the input direction and handle the movement/deceleration.
		# As good practice, you should replace UI actions with custom gameplay actions.

		if not wallclimbmode and not is_on_floor():
			$WallTimer.paused = true
			
			
		if Input.is_action_just_pressed("Slash") and cutitout == false and not is_on_floor() and $HoldRadius.alreadyholding == false:
			
			didbounce = false
			if $Cutitout.is_stopped():
				$Cutitout.wait_time = 0.3
				$Cutitout.start()
				$AnimationPlayer.play("DownSlash")
				cutitout = true
			if hitbounce == true and isDodge == false:
				velocity.y = JUMP_VELOCITY - 400
				if $FlickSound.playing == false:
					$FlickTimer.start()
					$FlickSound.play()
		
			
		
			
			
				

	
				
		if Input.is_action_pressed("Climb") and left == true and wallgrabstop == false and $HoldRadius.alreadyholding == false:
			wallclimbmode = true
			$AltruSprite.flip_h = true
			
		elif Input.is_action_pressed("Climb") and right == true and wallgrabstop == false and $HoldRadius.alreadyholding == false:
			wallclimbmode = true
			$AltruSprite.flip_h = false
			
		if left == true:
			
			$AltruSprite.flip_h = true
			
			
		if right == true:
			
			$AltruSprite.flip_h = false
			
		if direction > 0 and is_on_floor():
			$OnionSkin.scale.x = 1
			slow = 1
			if isDodge == false and wallclimbmode == false and cutitout == false and direction:
				$AnimationPlayer.play("Run")
			ducking = false
			duckloop = false
			lookup = false
			lookuploop = false
			Globals.slow = false
			Globals.run = true
			Globals.falling = false
			Globals.idle = false
		elif direction < 0 and is_on_floor():
			$OnionSkin.scale.x = -1
			slow = 1
			if isDodge == false and wallclimbmode == false and cutitout == false and direction:
				$AnimationPlayer.play("Run")
			ducking = false
			duckloop = false
			lookup = false
			lookuploop = false
			Globals.slow = false
			Globals.run = true
			Globals.falling = false
			Globals.idle = false
		if not is_on_floor() and direction > 0:
			$OnionSkin.scale.x = 1
			walk = false
			slow = 1
			direction = 1
		elif not is_on_floor() and direction < 0:
			$OnionSkin.scale.x = -1
			walk = false
			slow = 1
			direction = -1
		if Input.is_action_pressed("ui_left") and Input.is_action_just_released("ui_right") and didbounce == true:
			didbounce = false
		elif Input.is_action_pressed("ui_right") and Input.is_action_just_released("ui_left") and didbounce == true:
			didbounce = false
			

		if direction and wallclimbmode == false and constant == false and bounce == false and didbounce == false and nuhuh == false and stillslash == false or direction and wallclimbmode == false and constant == false and guything == true and nuhuh == false and stillslash == false:
			

			velocity.x = direction * (SPEED) 
		elif direction and wallclimbmode == false and constant == false and didbounce == true and guything == false and not velocity.x == 0:
			
			
			velocity.x = direction * SPEED * 2
			velocity.y += 4.4
		
				
		elif wallclimbmode == false and constant == true and bounce == false and stopdashvelo == false:
			velocity.x = direction * (SPEED + dodgepower) * 1.4
			velocity.y = directionyaxis * (dodgepower) * 1.6
			

		else:
			velocity.x = move_toward(velocity.x, 0, SPEED)
			slow = 1
			walk = false
		
		
			if is_on_floor() and wallclimbmode == false:
				tired = false
				closetoground = false
				if not $AnimationPlayer.current_animation == "Idle" and ducking == false and lookup == false and cutitout == false and not direction:
					$AnimationPlayer.play("Idle")
				Globals.slow = false
				Globals.run = false
				Globals.falling = false
				Globals.idle = true
			if is_on_floor() and wallclimbmode == true and Input.is_action_pressed("ui_down"):
				wallclimbmode = false
				
		if not direction and wallclimbmode == false and constant == false and didbounce == true and guything == false:
			guything = true
		if not direction and not directionyaxis and wallclimbmode == false and constant == true and didbounce == false:
			stopdashvelo = true
		if direction < 0 and wallclimbmode == false or direction < 0 and waitDodge == true:
			$AltruSprite.flip_h = true
		if direction > 0 and wallclimbmode == false or direction > 0 and waitDodge == true:
			$AltruSprite.flip_h = false
		if Input.is_action_just_pressed("ui_accept") and closetoground == true:
			savejump = true
		if Input.is_action_pressed("ui_accept"):
			wallclimbmode = false
			ducking = false
			lookup = false

		Globals.velox = velocity.x
		Globals.veloy = velocity.y
		


		move_and_slide()

		prevVelocity = velocity
			
		velocity.y = lerp(prevVelocity.y, velocity.y, 0.01)
		
		if nuhuh == true and $Wallbounce.is_stopped():
			$Wallbounce.start()
	elif dead == false and debug == true:
		Globals.velox = velocity.x
		Globals.veloy = velocity.y
		
		

		move_and_slide()

		
			
		set_collision_mask_value(2, false)
		set_collision_mask_value(4, false)
		set_collision_mask_value(1, false)
		$AreaDangerDetection/CollisionShape2D.disabled = true
		var shiftspeeddebug = 1
		if Input.is_action_pressed("Dodge"):
			shiftspeeddebug = 2
		elif Input.is_action_just_released("Dodge"):
			shiftspeeddebug = 1
		if direction:
			velocity.x = direction * (SPEED) * shiftspeeddebug
		else:
			velocity.x = move_toward(velocity.x, 0, SPEED)
		if directionyaxis:
			velocity.y = directionyaxis * SPEED * shiftspeeddebug
		else:
			velocity.y = move_toward(velocity.y, 0, SPEED)
	if Input.is_action_just_pressed("Dodge") and canDodge == true and waitDodge == false and isDodge == false and direction and not debug or Input.is_action_just_pressed("Dodge") and canDodge == true and waitDodge == false and isDodge == false and directionyaxis and not debug:
		dashrandom = round(rng.randf_range(1,6))
		aaaaaa = false
		if didbounce == true:
			out = true
		rng.randomize()
		if dashrandom == 1:
			$DashSound.pitch_scale = 1
			$DashSound.play()
		elif dashrandom == 2:
			$DashSound.pitch_scale = 0.94
			$DashSound.play()
		elif dashrandom == 3:
			$DashSound.pitch_scale = 0.90
			$DashSound.play()
		elif dashrandom == 4:
			$DashSound.pitch_scale = 1.02
			$DashSound.play()
		elif dashrandom == 5:
			$DashSound.pitch_scale = 1.08
			$DashSound.play()
		elif dashrandom == 6:
			$DashSound.pitch_scale = 1.10
			$DashSound.play()
		$WallGoneTimer.stop()
		leftwallgone()
		rightwallgone()
		$OnionSkin.emitting = true
		$constant.start()
		constant = true
		
		set_collision_mask_value(2, false)
		$AnimationPlayer.play("Dodge")
		isDodge = true
		canDodge = false
		waitDodge = true
		$DodgeTimer.start()
		$isDodgeTimer.start()
		dodgepower = dodge
		if tween:
			tween.stop()
		tween = create_tween()
		
		tween.tween_property(self, "dodgepower", 0, 0.18).set_ease(Tween.EASE_OUT)
		
		
		




func _on_dodge_timer_timeout() -> void:
	waitDodge = false
	pass # Replace with function body.


func _on_is_dodge_timer_timeout() -> void:
	bounce = false 
	isDodge = false
	$OnionSkin.emitting = false
	if not debug:
		set_collision_mask_value(2, true)
	pass # Replace with function body.


func _on_area_2d_body_entered(body: Node2D) -> void:
	if body.is_in_group("Tilemap") and not is_on_floor():
		closetoground = true
		ah = 0

	pass # Replace with function body.


func _on_area_2d_body_exited(body: Node2D) -> void:
	if body.is_in_group("Tilemap"):
		closetoground = false
	pass # Replace with function body.


func _on_wall_grab_body_entered(body: Node2D) -> void:
	
	$WallGoneTimer.stop()
	if body.is_in_group("Tilemap") and grabbing == false and $HoldRadius.alreadyholding == false:
		right = true
	pass # Replace with function body.


func _on_wall_grab_body_exited(body: Node2D) -> void:
	if body.is_in_group("Tilemap") and $WallGoneTimer.is_stopped():
		$WallGoneTimer.start()
		wallclimbmode = false
		right = false
		if not Input.is_action_pressed("ui_accept") and not is_on_floor() and not Input.is_action_pressed("ui_down") and tired == false and dead == false:
			velocity.y -= 160
			$AnimationPlayer.play("Jump")
	pass # Replace with function body.


func _on_wall_grab_2_body_entered(body: Node2D) -> void:
	
	$WallGoneTimer.stop()
	if body.is_in_group("Tilemap") and grabbing == false and $HoldRadius.alreadyholding == false:
		left = true
	pass # Replace with function body.


func _on_wall_grab_2_body_exited(body: Node2D) -> void:
	if body.is_in_group("Tilemap") and $WallGoneTimer.is_stopped():
		$WallGoneTimer.start()
		wallclimbmode = false
		left = false
		if not Input.is_action_pressed("ui_accept") and not is_on_floor() and not Input.is_action_pressed("ui_down") and tired == false and dead == false:
			velocity.y -= 160
			$AnimationPlayer.play("Jump")
	pass # Replace with function body.


func leftwallgone():
	left = false
	wallclimbmode = false
	
	pass

func rightwallgone():
	right = false
	wallclimbmode = false
	pass
		
func _on_wall_timer_timeout() -> void:
	tired = true
	pass # Replace with function body.


func _on_constant_timeout() -> void:
	constant = false
	fallfaster = true
	pass # Replace with function body.


func _on_area_danger_detection_body_entered(body: Node2D) -> void:
	if body.is_in_group("Danger"):
		Dead()
		pass # Replace with function body.


func _on_wall_grab_stop_timeout() -> void:
	wallgrabstop = false
	pass # Replace with function body.


func _on_wall_gone_timer_timeout() -> void:
	if left == true:
		leftwallgone()
	if right == true:
		rightwallgone()
	pass # Replace with function body.
	


func _on_coyote_jump_timeout() -> void:
	cantjump = true
	pass # Replace with function body.
	
func _input(event: InputEvent) -> void:
	if dead == false:
		if event is InputEventJoypadButton and dead == false:
			controller = true
		elif event is InputEventKey and dead == false:
			controller = false


func _on_wallbounce_timeout() -> void:
	nuhuh = false
	pass # Replace with function body.


func _on_cutitout_timeout() -> void:
	cutitout = false
	stillslash = false
	horizontalslash = false
	pass # Replace with function body.


func _on_downward_bounce_area_entered(area: Area2D) -> void:
	
	if area.is_in_group("Hit Mark"):
		
		hitbounce = true
		alreadyreleasedslash = false
		
	pass # Replace with function body.
	


func _on_downward_bounce_area_exited(area: Area2D) -> void:
	if area.is_in_group("Hit Mark"):
		hitbounce = false
	pass # Replace with function body.


func _on_duck_down_timeout() -> void:
	if $AnimationPlayer.current_animation == "Duck":
		duckloop = true
		$AnimationPlayer.play("Duck_loop")
	elif $AnimationPlayer.current_animation == "Lookup":
		lookuploop = true
		$AnimationPlayer.play("Lookup_loop")
	elif Input.is_action_just_pressed("ui_down") and Input.is_action_just_pressed("ui_up"):
		ducking = false
		duckloop = false
		lookup = false
		lookuploop = false
	pass # Replace with function body.


func _on_walkingsoundcollison_body_entered(body: Node2D) -> void:
	if body.is_in_group("Tilemap"):
		$WalkingSound.stream = rock
		
		
	elif body.is_in_group("TilemapPlatform"):
		$WalkingSound.stream = wood
	pass # Replace with function body.


func _on_walkingsoundcollison_body_exited(_body: Node2D) -> void:
	
	pass # Replace with function body.


func _on_flick_timer_timeout() -> void:
	$FlickSound.stop()
	pass # Replace with function body.


func _on_jump_finished() -> void:
	$Jump.stop()
	pass # Replace with function body.

func Dead() -> void:
	$PopDeath_kwahmah_02.play()
	leftwallgone()
	rightwallgone()
	$Climbing.stop()
	$Chirps.stop()
	$WalkingSound.stop()
	dead = true
	canDodge = false
	velocity.y = 0
	pausedframe(0.05, 0.3)
	if is_on_floor() and dead == true:
		$AnimationPlayer.speed_scale = 0.6
	if not is_on_floor() and dead == true:
		$AnimationPlayer.speed_scale = 0.5
	$AnimationPlayer.play("Pop Death")
	$OnionSkin.emitting = false
	var playoutro = get_node("../Marker2D/Camera2D/AnimationPlayer")
	await get_tree().create_timer(0.6).timeout
	playoutro.play("Transition Outro")
	$WallGrab.monitoring = false
	$WallGrab2.monitoring = false
	await get_tree().create_timer(0.5).timeout
	Globals.reset = true
	
	if Globals.cam == 1:
		global_position = $"../Node/Respawnpos1".global_position
	elif Globals.cam == 2:
		global_position = $"../Node/Respawnpos2".global_position
	elif Globals.cam == 3:
		global_position = $"../Node/Respawnpos3".global_position
	elif Globals.cam == 4:
		global_position = $"../Node/Respawnpos4".global_position
	elif Globals.cam == 5:
		global_position = $"../Node/Respawnpos5".global_position
	elif Globals.cam == 6:
		global_position = $"../Node/Respawnpos6".global_position
	elif Globals.cam == 7:
		global_position = $"../Node/Respawnpos7".global_position
	elif Globals.cam == 8:
		global_position = $"../Node/Respawnpos8".global_position
	elif Globals.cam == 9:
		global_position = $"../Node/Respawnpos9".global_position
	elif Globals.cam == 10:
		global_position = $"../Node/Respawnpos10".global_position
	
	await get_tree().create_timer(0.5).timeout
	$WallGrab.monitoring = true
	$WallGrab2.monitoring = true
	playoutro.play("Transition Intro")
	Globals.reset = false
	dead = false
	left = false
	right = false

func pausedframe(timeScale, dur):
	Engine.time_scale = timeScale
	await(get_tree().create_timer(dur * timeScale).timeout)
	Engine.time_scale = 1.0
	pass

So, to answer your earlier question: Yes, you can put it in a custom function. You can then call that function from physics_process(), and at least your code will be a little easier to read. Your code is currently what we would call spaghetti code. It took me a while to parse and I have a number of suggestions for readability as well as speed and memory usage.

We will start with your if statement that calls dodge:

	if Input.is_action_just_pressed("Dodge") 
		and canDodge == true 
		and waitDodge == false 
		and isDodge == false 
		and direction 
		and not debug 
	or Input.is_action_just_pressed("Dodge") 
		and canDodge == true 
		and waitDodge == false 
		and isDodge == false 
		and directionyaxis
		and not debug:

This seems to basically come down to the fact that you can only dash if you are moving left or right - or up or down. If velocity is (0,0), dash does nothing.

	if Input.is_action_just_pressed("Dodge") 
		and canDodge == true 
		and waitDodge == false 
		and isDodge == false 
		and velocity != Vector2.ZERO 
		and not debug:
	if Input.is_action_just_pressed("Dodge") and canDodge == true and waitDodge == false and isDodge == false and velocity != Vector2.ZERO and not debug:
		execute_dash()

(The second one is the one to use in GDScript.)

		dashrandom = round(rng.randf_range(1,6))

There is no reason to declare this variable at the top of the file. You don’t use it anywhere else in your code. You’ve scoped this variable at a higher level than necessary, so it’s taking up space in RAM even when the character isn’t dashing.

		aaaaaa = false

I have no idea what this does. Don’t care. You might consider a more descriptive name for future you. Still good you added all the code because we can see it’s immaterial to the issue.

		if didbounce == true:
			out = true

Same as above.

		rng.randomize()

This doesn’t do anything. You’ve already gotten your number up above. You don’t need to call randomize() every time.

		if dashrandom == 1:
			$DashSound.pitch_scale = 1
			$DashSound.play()
		elif dashrandom == 2:
			$DashSound.pitch_scale = 0.94
			$DashSound.play()
		elif dashrandom == 3:
			$DashSound.pitch_scale = 0.90
			$DashSound.play()
		elif dashrandom == 4:
			$DashSound.pitch_scale = 1.02
			$DashSound.play()
		elif dashrandom == 5:
			$DashSound.pitch_scale = 1.08
			$DashSound.play()
		elif dashrandom == 6:
			$DashSound.pitch_scale = 1.10
			$DashSound.play()

There are cleaner ways of doing this.

const dash_pitch: Array[float] = [0.90, 0.94, 1.0, 1.02, 1.08, 1.10] #Top of the file

		dash_random_pitch = round(rng.randi_range(0,5))
		$DashSound.pitch_scale = dash_pitch[dash_random_pitch]
		$DashSound.play()

Alternately, in the $DashSound object you could change the Stream to AudioStreamRandomizer, add your dash sound stream into it, and set Random Pitch to 1.1 (which would cover 0.90 to 1.10).

		$WallGoneTimer.stop()
		leftwallgone()
		rightwallgone()
		$OnionSkin.emitting = true
		$constant.start()
		constant = true
		
		set_collision_mask_value(2, false)
		$AnimationPlayer.play("Dodge")
		isDodge = true
		canDodge = false
		waitDodge = true
		$DodgeTimer.start()
		$isDodgeTimer.start()

Skipping this.

		dodgepower = dodge

The variable dodge always equals 1600.0 according to your code. I recommend making dodge a constant.

		if tween:
			tween.stop()
		tween = create_tween()
		
		tween.tween_property(self, "dodgepower", 0, 0.18).set_ease(Tween.EASE_OUT)

The best thought I have, and @gertkeno may have a better one, is that you should probably be lerping this, not tweening it.

dodgepower = lerp(dodgepower, 0.0, 0.18)

Also this code should probably be here:

		elif wallclimbmode == false and constant == true and bounce == false and stopdashvelo == false:
			dodgepower = lerp(dodgepower, 0.0, 0.18)
			velocity.x = direction * (SPEED + dodgepower) * 1.4
			velocity.y = directionyaxis * (dodgepower) * 1.6

And the dash code ends up being:

const dash_pitch: Array[float] = [0.90, 0.94, 1.0, 1.02, 1.08, 1.10] #Top of the file

func execute_dash() -> void:
		dash_random_pitch = round(rng.randi_range(0,5))
		$DashSound.pitch_scale = dash_pitch[dash_random_pitch]
		$DashSound.play()

		aaaaaa = false
		if didbounce == true:
			out = true
		$WallGoneTimer.stop()
		leftwallgone()
		rightwallgone()
		$OnionSkin.emitting = true
		$constant.start()
		constant = true
		
		set_collision_mask_value(2, false)
		$AnimationPlayer.play("Dodge")
		isDodge = true
		canDodge = false
		waitDodge = true
		$DodgeTimer.start()
		$isDodgeTimer.start()
		dodgepower = dodge
1 Like

Thank you so much! The dash is working the same on any fps now. Also thank you for simplifying my audio randomizer for my dash as well. I am grateful for your help!

1 Like

I’m really glad I could help and that you appreciate it. In general, I would recommend looking up variable scope, and learning about that so that you can reduce the number of variables at the top of your script. You can also separate out (refactor) more of your code the way I did with Dash to make it a little more readable.

1 Like