Disable a CollisionShape2D's collision detection

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lavaduder
:warning: Old Version Published before Godot 3 was released.

I have a animationplayer node that swaps the collisionshape2D animations, but I don’t want the collision shape to be active while the animations are not playing.

I was wondering if there was a way to disable the collision detection in CollisionShape2D. When I mean collision detection I don’t mean it as a trigger like set_trigger(false) that can still be set off. I mean to turn it off completely, and have it enabled again when desired. so queue_free() is also out of the question.

:bust_in_silhouette: Reply From: eons

Like removing all the layers and/or masks?

Areas can just set off monitoring and monitored status or turn off both layer and masks, the current behavior is kind of buggy (they seem to look for layers and masks instead of masks only, and react when not monitoring but are monitored).


Btw, I’m talking about the CollisionObject here (the parent), not the CollisionShape node because it is just a helper that uses the same shape resource as the parent.

If setting it to a different layer/mask will stop it from interacting with all objects/other collisionshapes, but keep it’s animations intact, then yes. Tell me how to send it to a different layer/mask.

By the way I’m using Godot 2.1.3

lavaduder | 2017-04-26 08:05

Basically, layers are where the bodies are (detected) and mask where they look for other bodies.

On script, PhysicBodies and Areas have layer_mask methods for layers and collision_mask methods for masks (confusing names).
PhysicsBody2D — Godot Engine (stable) documentation in English

The “bit” ones refer to the checkboxes you see on the inspector, the other uses an int but as binary (because is easier to operate multiple flags with bitwise operations).

TileMap have this too.

And Areas also have monitoring status:
Area2D — Godot Engine (stable) documentation in English

eons | 2017-04-26 13:27