Character bouncing when moving down a slope

Godot Version

4.3.stable

Question

Hey, I’m trying to make my first game prototype. I want my character to climb slopes, and it does so well, but it’s bouncing it’s way down from it:

Here’s the code:

extends CharacterBody2D


const SPEED = 250.0
# var speed_multiplier = 1.0
const JUMP_VELOCITY = 400.0
# var jump_velocity_multiplier = 1.0


func _physics_process(delta) -> void:
	
	# Gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta  
	
	# Walking.
	var walk_input = Input.get_axis("ui_left", "ui_right")
	if is_on_floor():
		velocity = velocity.move_toward(get_floor_normal().rotated(deg_to_rad(90)) * walk_input * SPEED, delta * 720)
	
	else:
		velocity.x = move_toward(velocity.x, walk_input * SPEED, delta * 360)
	
	# Jumping.
	if Input.is_action_pressed("ui_accept") and is_on_floor():
		velocity += (Vector2.UP + get_floor_normal()) / 2 * JUMP_VELOCITY
	else:
		apply_floor_snap()
	
	move_and_slide()
	print(velocity.normalized())

Any ideas how to fix this?

Maybe apply a constant downward velocity:

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

that didn’t help at all. maybe its something to do with apply_floor_snap()?

you can try to change the floor_snap_length-property

In Godot 3.x you can use “move_and_slide_with_snap()” instead of “move_and_slide()”. But in 4.x you need to use “move_and_slide()” with the floor_snap_length property.