0 votes

Everytime my character fall into a slope, it slides down a little bit. It's not something that is really notorious, but it will mess up my animation. I've tried different tutorials from the docs and from the internet and I always get stuck in the same issue D:

Here is a gif of what happens when my character fall into a slope:
enter image description here

And if I keep jumping, it keep sliding:

enter image description here

I have also tried to change the gravity when it hit the slope, the y velocity, but without success.

Anyone has dealed with this issue before? Anyone have any idea of how to stop sliding?

Here is my code:

extends KinematicBody2D

export (int) var run_speed = 100
export (int) var jump_speed = -400
export (int) var gravity = 1200

var velocity = Vector2()
var jumping = false
var right
var left
var jump
var jump_pressed
var jump_cut
var min_velocity_y = 400
var inicial_gravity = gravity

func get_input():
    velocity.x = 0
    right = Input.is_action_pressed('ui_right')
    left = Input.is_action_pressed('ui_left')
    jump = Input.is_action_just_pressed('ui_select')
    jump_pressed = Input.is_action_pressed('ui_select')
    jump_cut = Input.is_action_just_released('ui_select')

    if jump and is_on_floor():
        jumping = true
        velocity.y = jump_speed
    if velocity.y < 0 && !jump_pressed:
        velocity.y = 0
    if right:
        velocity.x += run_speed
    if left:
        velocity.x -= run_speed

func _physics_process(delta):
    get_input()
    velocity.y += gravity * delta
    if jumping and is_on_floor():
            jumping = false
    if velocity.y >= min_velocity_y:
        velocity.y = min_velocity_y
    velocity = move_and_slide(velocity, Vector2(0, -1), 5, 4, 0.87)
    print(velocity.y)

(and I'm sorry for my bad english ;-;)
(not native english speaker here >...>)

asked Jun 10 in Engine by rless (16 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 How to use this Q&A? before posting your first questions.