0 votes

I'm just learning Godot. This works perfectly for a basic character controller, but can someone help me understand why my constant SPEED needs to be set so high for adequate player speed? 10X higher than gravity?

extends KinematicBody2D

var velocity = Vector2()
const SPEED = 10000
const GRAVITY = 1000
const JUMP = 500


func _process(delta):
    _get_input(delta)

    velocity.y += GRAVITY * delta
    velocity = move_and_slide(velocity, Vector2.UP)

func _get_input(delta):
    var movement = -int(Input.is_action_pressed("left")) + int(Input.is_action_pressed("right"))
    velocity.x = movement * SPEED * delta

    if is_on_floor():
        if Input.is_action_just_pressed("space"):
            velocity.y -= JUMP
Godot version 3.3
in Engine by (17 points)

1 Answer

+1 vote
Best answer

This is because you're multiplying it by delta, which is the time since the last frame in seconds, so it's a very small number. The move and slide function automatically multiplies the argument by delta itself so it's being multiplied by delta twice. Don't multiply the speed by delta.

by (7,190 points)
selected by

Oh! I didn't realize that about moveandslide. Thank you!

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.