Hey so, the code I’m showing works but what I want to know is they’re any redundant code in this block. I’m still relatively new to Godot so idk if the things I’m doing is not needed or can be shorten.
class_name PlayerState extends LimboState
@export var player : PlayerController = agent as PlayerController
@export var action_anims : AnimationPlayer
@onready var input: PlayerInput = %Input
@onready var state_machine: LimboHSM = %StateMachine
static var direction: float
static var last_direction: float
static var speed: float
static var acceleration: float
static var deceleration: float
static var jump_force: float
static var gravity: float
static var can_air_combo: bool = true
static var has_jumped: bool = false
static var jump_buffered: bool = false
func apply_movement() -> void:
direction = blackboard.get_var(BBNames.direction_var)
speed = blackboard.get_var(BBNames.speed_var)
acceleration = blackboard.get_var(BBNames.acceleration_var)
deceleration = blackboard.get_var(BBNames.deceleration_var)
var acceleration_factor: float = speed * acceleration
var deceleration_factor: float = speed * deceleration
if not is_zero_approx(direction):
player.velocity.x = move_toward(
player.velocity.x, speed * direction, acceleration_factor)
blackboard.set_var(BBNames.last_direction_var, direction)
last_direction = blackboard.get_var(BBNames.last_direction_var)
else:
player.velocity.x = move_toward(player.velocity.x, 0.0, deceleration_factor)
player.move_and_slide()
func apply_jump_force() -> void:
jump_force = blackboard.get_var(BBNames.jump_force_var)
player.velocity.y = -jump_force
func apply_gravity(delta: float) -> void:
if player.velocity.y < 0.0:
gravity = blackboard.get_var(BBNames.jump_gravity_var)
else:
gravity = blackboard.get_var(BBNames.fall_gravity_var)
if not player.is_on_floor():
player.velocity.y += gravity * delta
func apply_coyote_timer(coyote_timer: Timer, input_pressed: bool) -> void:
if has_jumped:
return
if input_pressed and not coyote_timer.is_stopped():
apply_jump_force()
has_jumped = true
coyote_timer.stop()
func apply_jump_buffer(buffer_timer: Timer, input_pressed: bool) -> void:
if jump_buffered:
return
if input_pressed:
jump_buffered = true
buffer_timer.start()
Return type is irrelevant. If you’re asking for redundancies in the code, you need to post all of the code that gets executed. Your code calls some code in Blackboard class and it’s impossible to tell if there are redundancies in there if you don’t post its code.
I’ve looked at the profiler but don’t now really what is specifically it’s saying. Is there documentation on it or video guide on how to read it?
like for the apply movement function in player state, is any code that would be considered redundant? if you have questions on some parts of it i’ll answer it
Me not knowing that much about something gives me an annoying nagging feeling that i’m doing something wrong even know they’re a many ways to do it so that’s the main reason i’m asking.