Godot Version
4.4
Question
I’m making a PvZ style tower defense game, and for said game I have a tower that shoots a bullet every so often.
I’ve recently discovered Engine.set_max_fps()
and decided to test out slower frame rates to see how things interact in said frame rates.
Something important to know is that basically everything that moves in the project is just an Area2D, rather than a CharacterBody2D, which means I don’t have access to move_and_slide()
, which already has Delta Time applied from what I hear.
This means to move something I do something basically similar to position.x += moveSpeed * moveDir
Big surprise, on slower frame rates, things move slower.
I decided to try fixing the bullets to conform to Delta Time as they are the simplest object in the game currently, so I do position.x += moveSpeed * moveDir * delta
, where moveSpeed
is how far an object moves in pixels, moveDir
is either -1 or 1 for left and right movement, and delta
comes from the _process()
function.
This properly works in making the bullets move the same speed across all frame rates, however, now they are moving way too slow. After many attempts at trial and error, I’ve come up short in terms of solutions. I’ve tried rearranging the order of operations, adding and removing parentheses, and much more, but 1 of 3 things happened with each solution I’ve tried:
The bullets instantly move to the center of the screen
The bullet speed is still super slow
The bullet speed is slower/faster based on the frame rate, as if Delta Time was never applied at all.
I’ve tried position.x += (movespeed * delta * 100) * moveDir
but I’m not entirely sure how good or long-term of a solution that will end up being.
I’m a bit stuck at this point. Are there any possible solutions I might’ve missed? I’m still somewhat early enough into the project where replacing every moving object with a CharacterBody2D isn’t a completely insane idea, however I am considering it a last-resort solution to this problem.