0 votes

I'm new to godot and I also have no experience with any other game engine, so it's my first time using "delta" but for some reason using it makes all my movement variables not work properly and I have to readjust the values.

I want to know if this is normal and so far have found no one else with this issue.

Heres all of my code I have used "delta" on:
Note: You can see the values I had before using "delta"

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 1200 # 20
const ACCELERATION = 13000 #50
const MAX_SPEED = 30000 #200
const JUMP_HEIGHT = -33000 # -550
const WALLJUMP = 1000 # 300
const WJ_ACCELERATION = -1000 # 10
const WJ_MAX_SPEED = 5000 # 500

onready var Player_Health = get_node("Health")
onready var Left_Inputs = get_node("gui/left_inputs")
onready var Right_Inputs = get_node("gui/right_inputs")
onready var UpRight_Inputs = get_node("gui/upright_inputs")
onready var gui = get_node("gui/Interface")
onready var Settings = get_node("Camera2D/CanvasLayer/Settings")
onready var Interact = get_node("Instructions")

var Poisoned = false
var Natural_Heal = false

var motion = Vector2()

func _physics_process(delta):
    motion.y += GRAVITY * delta
    var friction = false

var Hitbox_Bodies = get_node("Hitbox").get_overlapping_bodies()

MOVEMENT

if !Settings.menu:
    if Input.is_action_pressed("ui_right"):
        motion.x = min(motion.x+ACCELERATION, MAX_SPEED) * delta
        $Sprite.flip_h = false
        $Sprite.play("Run")
        Interact.hide()
        if is_on_floor():
            if(!$WalkAudio.is_playing()):
                $WalkAudio.play()
        else:
            $WalkAudio.stop()
    elif Input.is_action_pressed("ui_left"):
        motion.x = max(motion.x-ACCELERATION, -MAX_SPEED) * delta
        $Sprite.flip_h = true
        $Sprite.play("Run")
        Interact.hide()
        if is_on_floor():
            if(!$WalkAudio.is_playing()):
                $WalkAudio.play()
        else:
            $WalkAudio.stop()
    else:
        $Sprite.play("Idle")
        friction = true
        $WalkAudio.stop()

    if is_on_floor():
        if Input.is_action_pressed("ui_up"):
            motion.y = JUMP_HEIGHT * delta
            if(!$JumpAudio.is_playing()):
                $JumpAudio.play()
        if friction:
            motion.x = lerp(motion.x, 0, -50) * delta #0.2
    else:
        if motion.y < 0:
            $Sprite.play("Jump")
        else:
            $Sprite.play("Fall")
        if friction:
            motion.x = lerp(motion.x, 0, -55) * delta # 0.05

WALL JUMP

    for body in Hitbox_Bodies:
        if body.name.begins_with("Jump_Wall_Left"):
            if Input.is_action_pressed("ui_left"):
                motion.y = min(motion.y-WJ_ACCELERATION, WJ_MAX_SPEED) * delta
                $Sprite.flip_h = false
            if Input.is_action_pressed("ui_right"):
                if Input.is_action_pressed("ui_up"):
                    motion.y = JUMP_HEIGHT * delta
                    motion.x = WALLJUMP
                    if(!$JumpAudio.is_playing()):
                        $JumpAudio.play()
        if body.name.begins_with("Jump_Wall_Right"):
            if Input.is_action_pressed("ui_right"):
                motion.y = min(motion.y-WJ_ACCELERATION, WJ_MAX_SPEED) * delta
                $Sprite.flip_h = true
            if Input.is_action_pressed("ui_left"):
                if Input.is_action_pressed("ui_up"):
                    motion.y = JUMP_HEIGHT * delta
                    motion.x = -WALLJUMP
                    if(!$JumpAudio.is_playing()):
                        $JumpAudio.play()

By the way, this is my first time posting an issue, let me know if I'm missing something

in Engine by (65 points)

1 Answer

+2 votes

Upon futher investigation I realized that if you are using "moveandslide" you shouldn't use "delta"

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.

I will keep the post, maybe it could help someone else.

by (65 points)
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.
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 webmaster@godotengine.org with your username.