Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Entity2020 studios |
I’m trying to program a bullet in Godot 4 that returns to the player 1 second after being fired. This is the code:
var MoveSpeed = 0
@warning_ignore("unused_parameter")
func _process(delta):
if PlayerData.StayNearplayer == false:
MoveSpeed = 3
@warning_ignore("unused_parameter")
func _physics_process(delta):
if PlayerData.StayNearplayer == false:
$GoBack.start()
$".".rotation.y = PlayerData.PlayerDirection
position.z -= MoveSpeed
func _on_go_back_timeout():
PlayerData.StayNearplayer = true
MoveSpeed = 0
But for some reason, the timer doesn’t work, and the bullet can only be fired once.
This is the script for firing the bullet, in case that helps.
if Input.is_action_pressed("Shoot") and PlayerData.StayNearplayer == true:
PlayerData.PlayerDirection = $Player.rotation.y
PlayerData.StayNearplayer = false
$Bullet.show()
Is there any way for me to fix this issue?
Hi
The code looks correct (Unless if the timer isn’t a child of the node that has this script) so it could be something in the editor. Did you change oneshot
or autostart
?
Or didn’t connect the right signal to the right function?
GameSchool | 2023-05-28 12:57
The oneshot option is on, and autostart is off. And the signal seems to be linked to the right thing. I’ll have a closer look at the code to see if anything’s wrong…
Entity2020 studios | 2023-05-28 13:11