안녕하세요, 수업 프로젝트로 Godot 4에서 작은 탑다운 슈터를 만들고 있어요. 문제가 두 개인데, 버그가 하나일 수도 있고 두 개일 수도 있어요.
1. 폭탄. 플레이어가 폭탄을 주우면 wave manager의 kill_all()을 호출해요. 적이 10마리면 5마리만 죽어요. 나머지 5마리는 남아 있고 웨이브가 끝나지 않아요. 폭탄 전후로 alive_enemies.size()를 출력해 봤어요. 전에는 10이라고 나오고, 후에는 5라고 나와요. 폭탄이 프레임에서 잘못된 타이밍에 실행되는 건가 싶어서 call_deferred를 써 봤어요. 그래도 잘 모르겠어요. 예전 Godot 3 프로젝트에서는 이런 루프가 문제없이 됐어요.
func kill_all() -> void:
for e in alive_enemies:
e.take_damage(9999)
func _on_enemy_died(enemy: Enemy) -> void:
alive_enemies.erase(enemy)
score += 10
take_damage는 died를 emit하고, 그다음 queue_free()를 해요.
2. 이동. 부드럽게 하고 싶어서 _process에서 플레이어를 움직여요:
func _process(delta: float) -> void:
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = dir * speed
move_and_slide()
제 노트북은 괜찮아요. 144 Hz 모니터를 쓰는 친구는 플레이어가 더 빠르고 벽 모서리에 걸린다고 해요.
둘 다 프레임 타이밍 때문일까요? 아니면 서로 다른 버그일까요?
영어에서 번역·원문 보기Hello, small top-down shooter for class project, Godot 4. Two problem, maybe one bug, maybe two.
1. Bomb. Player pick up bomb, it call kill_all() on wave manager. With 10 enemy, only 5 die. The other 5 stay and the wave never clear. I print alive_enemies.size() before and after bomb. Before it say 10, after it say 5. I think maybe bomb run at wrong time in the frame, so I try call_deferred on it. Still confusing. In my old Godot 3 project a loop like this work fine.
func kill_all() -> void:
for e in alive_enemies:
e.take_damage(9999)
func _on_enemy_died(enemy: Enemy) -> void:
alive_enemies.erase(enemy)
score += 10
take_damage emit died, then queue_free().
2. Movement. I move player in _process because I want smooth:
func _process(delta: float) -> void:
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = dir * speed
move_and_slide()
My laptop is OK. Friend with 144 Hz monitor say player faster and stick on wall corner.
Is this frame timing for both? Or two different bug?