#why is my character moving so slow?

1 messages · Page 1 of 1 (latest)

quaint whale
#

(for reference this is a top down 2d game prototype thing)
i'm using the _physics_process() function with move_and_slide() like i'm supposed to, but even though my speed constant is set to 750, my character moves incredibly slow for whatever reason.

extends CharacterBody2D

class_name player

const SPEED = 750
const DASHSPEED = 0.1
const DASHDURATION = 0.2
const DASHCOOLDOWN = 0.5

var isDashing = false
var canDash = true
@export var isPlayerNear = false

func  _physics_process(delta):
    if !isDashing:
            velocity = Input.get_vector("left", "right","up", "down") * (SPEED * delta)
    move_and_slide()

func _process(_delta):
    if isPlayerNear:
        canDash = false
    else:
        canDash = true

func _input(event):
    if event.is_action_pressed("action") and canDash:
        if velocity != Vector2.ZERO:
            StartDash()

func StartDash():
    isDashing = true
    canDash = false
    var dashDirection = velocity.normalized()
    velocity = dashDirection * (SPEED * DASHSPEED)
    await get_tree().create_timer(DASHDURATION).timeout
    StopDash()

func StopDash():
    isDashing = false
    canDash = false
    velocity = Vector2.ZERO
    await get_tree().create_timer(DASHCOOLDOWN).timeout
    canDash = true

my previous solution was scaling everything down but it feels unorthodox to have to scale everything down to 0.03 and below just to make really high speed values work properly. what i gather from this is that it's either a really high speed value or really small assets, and i was wondering if i'm doing anything wrong because that would be really odd if that was the case.

warm vapor
#

i found the problem give me one minute

#

extends CharacterBody2D

class_name Player

const SPEED = 750
const DASHSPEED = 2.5
const DASHDURATION = 0.2
const DASHCOOLDOWN = 0.5

var isDashing = false
var canDash = true
@export var isPlayerNear = false

func _physics_process(delta):
if !isDashing:
velocity = Input.get_vector("left", "right", "up", "down") * SPEED
move_and_slide()

func _process(_delta):
canDash = !isPlayerNear and !isDashing

func _input(event):
if event.is_action_pressed("action") and canDash and velocity.length() > 0:
start_dash()

func start_dash():
isDashing = true
canDash = false
var dashDirection = velocity.normalized()
velocity = dashDirection * SPEED * DASHSPEED
await get_tree().create_timer(DASHDURATION).timeout
stop_dash()

func stop_dash():
isDashing = false
await get_tree().create_timer(DASHCOOLDOWN).timeout
canDash = true

#

try this

quaint whale
#

that worked, thanks! what exactly was changed here and why did it make the character faster?

#

wait, i just realized that speed isn't being multiplied by delta anymore. that fixes the speed but isn't it dangerous? won't that make the speed work differently with fps changes? or is that not an issue in this case?

warm vapor
#

The main issues were that movement was too slow because SPEED was incorrectly multiplied by delta, making the character move much slower than intended. The dash was also too weak because DASHSPEED was set to 0.1, making it slower than normal movement instead of faster. Additionally, after dashing, velocity = Vector2.ZERO caused the player to stop abruptly instead of continuing movement. The dash logic also allowed dashing even when the player wasn’t moving, leading to strange behavior, and isPlayerNear could disable dashing even while dashing was in progress. These issues were fixed by removing delta from movement calculations, increasing DASHSPEED to 2.5, preventing abrupt stops after dashing, ensuring dashing only triggers when moving, and refining the canDash logic to avoid unwanted interruptions.

warm vapor
# quaint whale wait, i just realized that speed isn't being multiplied by delta anymore. that f...

emoving delta is not an issue in this case because Godot’s move_and_slide() function already accounts for delta internally. If SPEED were multiplied by delta manually, it would effectively apply the frame rate scaling twice, making the character move too slowly, especially at lower FPS. Using delta is necessary when modifying position directly (e.g., position += velocity * delta), but not when using built-in movement functions like move_and_slide(), which ensures consistent speed across different frame rates.

#

i hope you understand that 😄

quaint whale
#

i see, i understand that