0 votes

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.

Godot version 3.5.1
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.