![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ox0zOwra |
I’m using _physics_process() to check for player input every frame.
func _physics_process(delta):
check_for_keypresses(delta)
collision_check()
if shield <= 0:
emit_signal("player_died")
explode()
One of the keypresses I check for is related to firing weapons.
func check_for_keypresses(delta):
movement_check(delta)
if not cutscene_started:
fire_check()
charge_check()
debug_level_check()
I use a timer to flip a boolean that can be used to check if the player is able to fire weapons at the moment or not (the player’s delay between shots is measured in milliseconds):
func fire_check():
# fire button, isn't during heat sink failure, firerate timer
if Input.is_action_pressed("fire") and fire_conditions():
create_missile()
play_surreal_drive_sound()
play_gunshot_sound()
advance_fire_pattern()
generate_heat()
firerate_cooldown()
if Input.is_action_just_released("fire"):
stop_surreal_drive_sound()
$t_pattern_reset.start()
The problem shows up when I try to play the game at lower framerates (30 fps). I don’t actually believe that anyone will be able to play this game at a lower framerate than 60 fps, considering it’s rather small, but even then, with this method, the player’s firerate cannot exceed maximum fps - you cannot check for player input more than once per frame, which means your firerate caps at 60 bullets per second for 60 fps, 30 bullets per second for 30 fps, etc.
There are a few things I considered in this situation:
- searching up if Godot supports substepping (or something of the sort, the first result redirects me to the Unreal Engine page), but I haven’t got any results on that matter (and I don’t even know how substepping works, so it could be overkill for this game anyway)
- somehow putting user input (or the bullet creation functions themselves) outside of _(physics)_process, but I’m not exactly sure how, and when I googled the _input function, I learned that _process input is used because it has less latency for stuff like action games
- if none of those are possible, increasing bullet damage to compensate for the fact that firerate is tied to framerate, but that still doesn’t help the fact that this game’s firing mechanics will run differently at 30 or 15 fps (though reaching such a low framerate would probably mean you shouldn’t even be playing this game)
I’m kind of stuck on this one. I would appreciate some help on the matter.