Hi,
I'm a beginner to Godot, and I've been trying to make a 2D Platformer to start off.
However, I've been having an issue where my player slides down slopes. I've tried a few methods (such as following this tutorial https://www.youtube.com/watch?v=9l-tf97z2bg), but my character has acceleration and deceleration rather than constant speed, so there's still been a small bit of movement down slopes when the player decelerates.
For context, here's the movement code with sliding:
const FLOOR_NORMAL = Vector2.UP
export var walkSlip = 0.9
export var walkForce = 45
export var jumpForce = 1300.0
export var gravity = 3000.0
var velocity = Vector2.ZERO
func _physics_process(delta: float) -> void:
var _left = Input.get_action_strength("player_left")
var _right = Input.get_action_strength("player_right")
var _jump = Input.is_action_just_pressed("player_jump")
velocity.x += (_right - _left) * walkForce
velocity.x *= pow(walkSlip, delta*30)
velocity.y += gravity * delta
if (is_on_floor() and _jump):
velocity.y = -jumpForce
velocity = move_and_slide(velocity, FLOOR_NORMAL, true)
It feels like this problem's fairly common, but all the solutions I've found only deal with a single constant speed (setting the velocity variable instead of adding to it). A solution or point in the right direction would be greatly appreciated. Thanks.