0 votes

Hello,
I started using godot and try to make some tests.
But i'm blocked at this point :
I have a character (KinematicBody2D) and a tile map.
I can move him at the right or at the left, jump but i cant jump and move together.
When i try it go upper but dont move...
I think im not using correctly the moveandslide but i dont know how to do..

here is my code :

    extends KinematicBody2D


# Declare member variables here. Examples:
const GRAVITY = 200
const WALK_SPEED = 200
var velocity = Vector2()
var sur_sol = false
var delai_jump=0
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.

func get_input():
    velocity = Vector2()    
    if(Input.is_action_pressed("ui_right") == true):
        velocity.x += 1
    elif(Input.is_action_pressed("ui_left") == true):
        velocity.x -= 1
    if(Input.is_action_pressed("ui_down") == true):
        velocity.y += 1
    if(Input.is_action_pressed("ui_up") == true and is_on_floor()):
        delai_jump=20;

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
    get_input()
    if(delai_jump > 0):
        velocity.y -= 250
        delai_jump = delai_jump-1
    if(sur_sol == false):
        velocity.y += 12000*delta
    if(velocity.length() > 0):
        if(velocity.x < 0):
            $Sprite.flip_h = true
            velocity = velocity.normalized() * WALK_SPEED
            $Sprite.play("run")
        elif(velocity.x > 0):
            $Sprite.flip_h = false
            velocity = velocity.normalized() * WALK_SPEED
            $Sprite.play("run")
        else:
            $Sprite.play("jump")
    else:
        $Sprite.play("idle")
    print(velocity)
    if(is_on_floor()):
        sur_sol=true
    else:
        sur_sol=false
    move_and_slide(velocity, Vector2(0,-1))

Thanks for help

asked Mar 2 in Engine by hicode (12 points)

Hey, I'd recommend you watch a tutorial on how to make movement in Godot such as https://youtu.be/wETY5_9kFtA.

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.