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?