Dashing while theres isnt a direction input moves the player more than when there is

Godot Version

Godot 4.2


Basically, on a platformer im making to learn godot when the user is pressing a direction key the dash works as expected, but if the user isnt pressing any key the player moves a lot more, even tho the values im adding to the velocity are the same in both cases.

func _on_dash_timer_timeout():
	can_dash = true

# TODO: handle dash should just move the user backwards
func handle_dash(delta):
	if Input.is_action_just_pressed("dash") and can_dash:
		can_dash = false
		current_state = states.DASHING
		var input_direction = handle_input()
		var dash_force = (DASH_SPEED + ACCELERATION) * delta
		if input_direction != Vector2.ZERO:
			# Apply dash force in the direction of the pressed key
			input_direction = input_direction.normalized()
			velocity.x += dash_force * input_direction.x
			print("Moving value: ", dash_force * input_direction.x)
			# Apply dash force in the direction of the last pressed key
			velocity.x += dash_force * -last_pressed_direction
			print("Still value: ", dash_force * -last_pressed_direction)
		dash_timer.wait_time = DASH_COOLDOWN_TIMER
		dash_timer.start()  # Dash cooldown

Thanks in advance for any help/tips you can give me.

Where is this set? last_pressed_direction

This variable may be causing the overshoot but it’s not shown how it gets it’s value.

it is being set then the user presses a direction key.

# function to handle input
func handle_input() -> Vector2:
	var input_dir = Vector2.ZERO
	input_dir.x = Input.get_axis("move_left", "move_right") # returns -1 or 1
	if input_dir != Vector2.ZERO: # Only set the lates direction if we moved
		last_pressed_direction = input_dir
	return input_dir

This is input dash

This is still dash

dash_force * input_direction.x
dash_force * -last_pressed_direction

Should it not be last_pressed_direction.x?

1 Like

yeah, last night i modified a lot of thing one of them was leaving the last pressedd_direction as a Vector2 and work with the velocity like that but got nowhere… i think the problem is the whole movement implementation so i will re write everything from scratch and try to make it cleaner and easier to debug.

Thank you @pennyloafers

There is always the engine debugger

Since it’s in a physics loop it may be a little annoying but here is the trick if you don’t have a code block for the condition

If " my bad condition is true,like speed to high":

You can setup a bad condition check and hit the break point like this in code.

I guess the problem is elsewhere in the code. My guess is that when the player is moving there is some code to limit or slow walking speed, but when character is standing still that walking code was not being activated during a still dash.

1 Like

Thank you, ill give it a try and see if i can get that problem solved :smiley: