I'm a Godot newbie. I'm making a top down zombie shooter game just to explore the world of game dev. While trying to make automatic rifle, I found that it shot very inconsistently. How I did it was I first created a fire rate timer which splits the shots up for a certain amount of time. Once you shot, it would start timer, shoot, and change "shooting" to true. Once the timer timed-out, it would make "shooting" false allowing you to shoot again. The pistol works fine, as it's fire rate is 0.6 seconds per shot. But when I tried the rifle, with a fire rate of 0.2 seconds, it sometimes, didn't shoot, sometimes shot, it was a mess. Here's some code;
func _ready() -> void:
reloade = Timer.new()
$ZombieSpawntime.start()
firerate_timer = Timer.new()
firerate_timer.wait_time = Global.currentGuns[2]
firerate_timer.one_shot = true
firerate_timer.timeout.connect(self._on_shoot_timer_timeout)
add_child(firerate_timer)
^this was the onready function that made the timer. If your wondering what the Global. stuff is, I keep the player hot bar and guns in a nested array in a singleton.
func _input(event: InputEvent) -> void:
if reloading == false and ammo_in_mag > 0 and can_shoot and (Input.is_action_pressed("space") or Input.is_action_pressed("leftclick")):
can_shoot = false #you can only shoot when can_shoot is true
firerate_timer.start()
var bullet_instance = bullet.instantiate()
add_child(bullet_instance)
ammo_in_mag -= 1
$CanvasLayer/Control/Label.text = "Ammo: " + str(ammo_in_mag)
this input function controls when to shoot. It instantiates the bullet during this process.
func _on_shoot_timer_timeout(): can_shoot = true
this is the fire rate timeout function. Very simple, just enables shooting.
I've tried asking chatgpt, but he didn't give me any ideas on what to do. Since I got some of this off Youtube, I honestly can't think of another way to shoot bullets yet make it more optimized.
I'm a Godot newbie. I'm making a top down zombie shooter game just to explore the world of game dev. While trying to make automatic rifle, I found that it shot very inconsistently. How I did it was I first created a fire rate timer which splits the shots up for a certain amount of time. Once you shot, it would start timer, shoot, and change "shooting" to true. Once the timer timed-out, it would make "shooting" false allowing you to shoot again. The pistol works fine, as it's fire rate is 0.6 seconds per shot. But when I tried the rifle, with a fire rate of 0.2 seconds, it sometimes, didn't shoot, sometimes shot, it was a mess. Here's some code;
func _ready() -> void:
reloade = Timer.new()
$ZombieSpawntime.start()
firerate_timer = Timer.new()
firerate_timer.wait_time = Global.currentGuns[2]
firerate_timer.one_shot = true
firerate_timer.timeout.connect(self._on_shoot_timer_timeout)
add_child(firerate_timer)
^this was the onready function that made the timer. If your wondering what the Global. stuff is, I keep the player hot bar and guns in a nested array in a singleton.
func _input(event: InputEvent) -> void:
if reloading == false and ammo_in_mag > 0 and can_shoot and (Input.is_action_pressed("space") or Input.is_action_pressed("leftclick")):
can_shoot = false #you can only shoot when can_shoot is true
firerate_timer.start()
var bullet_instance = bullet.instantiate()
add_child(bullet_instance)
ammo_in_mag -= 1
$CanvasLayer/Control/Label.text = "Ammo: " + str(ammo_in_mag)
this input function controls when to shoot. It instantiates the bullet during this process.
func _on_shoot_timer_timeout(): can_shoot = true
this is the fire rate timeout function. Very simple, just enables shooting.
I've tried asking chatgpt, but he didn't give me any ideas on what to do. Since I got some of this off Youtube, I honestly can't think of another way to shoot bullets yet make it more optimized.
Share Improve this question asked Mar 2 at 14:54 oliver jamesoliver james 111 gold badge1 silver badge3 bronze badges1 Answer
Reset to default 0I'm not actually sure about the reason, but try to change https://docs.godotengine./en/stable/classes/class_timer.html#class-timer-property-process-callback . Timer is updated every physics frame, it's stated so in the docs. I wonder what happens if we process it every frame.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745119902a4612350.html
评论列表(0条)