0 votes

I am attempting my first project which is started from the 2D tutorial. I added a simple new_game function, but for some reason the CollisionShape2D for the player is still disabled and Mobs can't kill the player.

This is the 'body_entered' method for the Player that shows it's killed:

    hide()  # Player disappears after being hit.
    emit_signal("player_killed")
    print_debug("hit and dying")
    #defer so it's not disabled in the middle of a collision processing
    $CollisionShape2D.set_deferred("disabled", true)

The method called on the player on new game

func start(pos: Vector2) -> void:
    position = pos
    $CollisionShape2D.disabled = false
    show()

Tried doing $CollisionShape2D.set_deferred("disabled", false) but that didn't work

weird thing is it isn't disabled in the restart of in the Main class.

func restart():
    get_tree().call_group("mobs", "queue_free")

    while($Player/CollisionShape2D.disabled):
        print_debug("waiting I guess..2")
    new_game()

It never prints the debug statement there.

But after restart in the 'process' method in Player, I added a 'printdebug' statement if $CollisionShape2D.disabled to find that it was somehow disabled when playing.

The collision works normally in the game before the restart.

Godot version 3.2.3.stable.offical
in Engine by (14 points)
edited by

1 Answer

0 votes

So it never detects collision with player, but is never disabled according to print ?
Check if collision layers are befitting collision masks

by (2,410 points)

Sorry, I worded my post in kind of a weird order.
In the restart function, at least from what it seems in that loop, it's not disabled.

But it is disabled when checking the the '_process' method in the Player class afterwards.

And collision works before the restart, so I think I have the layers/masks correct.

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 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 webmaster@godotengine.org with your username.