Godot Version
4.6
Question
When I run my project the character’s speed feels a lot slower than expected but If I change it’s speed while the project is running (from 40 to 41 for example) it fixes itself. But this only works If I do this change everytime I run the project.
Also when I change the @export var speed to const speed this also seems to work properly. I feel like something might be wrong with my player controller script here:
extends CharacterBody2D
class_name PlayerController
@export var speed := 40.0
@export var jump_power = 28.0
@export var jump_damp = .11
@onready var coyote_timer = $CoyoteTimer
const speed_multiplier = 10.0
var jump_multipler = -45.9
var direction = 0
var can_coyote_jump = false
#const SPEED = 300.0
#const JUMP_VELOCITY = -400.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor() and can_coyote_jump == (false):
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("jump"):
if is_on_floor() or can_coyote_jump:
velocity.y = jump_power * jump_multipler
if can_coyote_jump:
can_coyote_jump = false
print("coyote jump")
if Input.is_action_just_released("jump") and velocity.y < 0:
velocity.y = velocity.y * jump_damp
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * speed * speed_multiplier
else:
velocity.x = move_toward(velocity.x, 0, speed * speed_multiplier)
var was_on_floor = is_on_floor()
move_and_slide()
if was_on_floor and !is_on_floor() and velocity.y >= 0:
can_coyote_jump = true
coyote_timer.start()
func _on_coyote_timer_timeout() -> void:
can_coyote_jump = false