Timeout signal has no effect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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 oneshotor 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

:bust_in_silhouette: Reply From: Entity2020 studios

I think I know the issue now…

if PlayerData.StayNearplayer == true:
	$Bullet.hide()
	$Bullet.position.x = $Player.position.x
	$Bullet.position.z = $Player.position.z
$Camera.position.x = $Player.position.x
$Camera.position.z = $Player.position.z
if Input.is_action_pressed("Shoot") and PlayerData.FirstPerson == true:
	$Bullet.show()
	PlayerData.PlayerDirection = $Camera.rotation.y
	PlayerData.StayNearplayer = false

This code has a section that hides the bullet and keeps it in the same position when StayNearPlayer is true. When the player attempts to shoot the bullet, the script that keeps it attached to the player is still active. I need to give the script an extra variable that tells it if the bullet is being fired.

:bust_in_silhouette: Reply From: klabri2104

var MoveSpeed = 0
var bulletCooldown = false

@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:
if bulletCooldown == false:
$GoBack.start()
$“.”.rotation.y = PlayerData.PlayerDirection
position.z -= MoveSpeed

func _on_go_back_timeout():
PlayerData.StayNearplayer = true
MoveSpeed = 0
bulletCooldown = false