Answers for "godot move and slide not working"

0

godot move and slide not working

1) You should not be using move_and_slide in _process(). Use _physics_process().
2) move_and_slide() uses pixels per second, so you should not multiply by delta

Per the docs for KinematicBody2D:

linearvelocity is a value in pixels per second. Unlike in for example moveand_collide, you should not multiply it with delta — this is done by the method.
Posted by: Guest on July-27-2021
0

godot move and slide not working

var spd = 500
var acceleration = 10
var jmpSpd = 800
var GRAVITY = 1300
var speed = Vector2()

func _ready():
    set_process(true)

func _process(delta):
    if Input.is_action_pressed("btn_jump") and is_on_floor():
        speed.y = -jmpSpd

    var desiredSpeed = 0
    if Input.is_action_pressed("btn_right"):
        desiredSpeed = spd
    elif Input.is_action_pressed("btn_left"):
        desiredSpeed = -spd
    speed.x += (desiredSpeed - speed.x)*acceleration*delta
    speed.y += GRAVITY*delta

    speed = move_and_slide(speed)
Posted by: Guest on July-27-2021

Code answers related to "godot move and slide not working"

Browse Popular Code Answers by Language