The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

So why doesn't this work?

onready var Enemy = $George
func _ready():
if Enemy.visible == false:
    $Timer.stop()
elif Enemy.visible == true:
    $Timer.start()

The timer does start after the enemy is visible but after he disappears it doesn't stop.

Godot version latest
in Engine by (24 points)

1 Answer

+1 vote
Best answer

Visibility on screen is not the same as visibility on the node. If you want to test if an object has left the screen, use a VisibilityNotifier2D

by (286 points)
selected by

Now i need to stop it when the enemy is not visible

func _physics_process(delta):
    if Enemy.health == 0:
        $Timer.stop()

This does not work,why?

So i made a timer that is 0.05 seconds that always runs but now it seems that the game over timer doesn't start again:

func _on_Timer2_timeout():
    if Enemy.visible == false:
        $Timer.stop()

I've made a test project that I believe implements what you're looking for. Have a look at it here: https://we.tl/t-LyZV8Ac8a3

Do you have like a discord i want to give you the source code to my game to see what's wrong,i don't want it shared here

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.