![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | ManiCus |
how can i enable and disable collisions from script
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | ManiCus |
how can i enable and disable collisions from script
![]() |
Reply From: | njamster |
By getting the nodes CollisionShape2D and setting its disabled
-property accordingly:
get_node("CollisionShape2D").disabled = true # disable
get_node("CollisionShape2D").disabled = false # enable
If you only want to disable collisions with certain but not all objects, take a look at collisions layers and masks.
thank u so much i love yaaaaaaa
ManiCus | 2020-02-11 16:56
I tried just this but I get an error saying:
E 0:00:02:0352 killzone.gd:11 @ _on_body_entered(): Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
<C++ Error> Condition “body->get_space() && flushing_queries” is true.
<C++ Source> servers/physics_2d/godot_physics_server_2d.cpp:654 @ body_set_shape_disabled()
killzone.gd:11 @ _on_body_entered()
here is my code… please help!!!
E 0:00:02:0352 killzone.gd:11 @ _on_body_entered(): Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
<C++ Error> Condition "body->get_space() && flushing_queries" is true.
<C++ Source> servers/physics_2d/godot_physics_server_2d.cpp:654 @ body_set_shape_disabled()
<Stack Trace> killzone.gd:11 @ _on_body_entered()
You will probably want to use set_deffered
to change the disabled value:
var home = $"Home".get_node("CollisionShape2D")
home.set_deferred("disabled", false)