0 votes

I have a CollisionShape2D in a KinematicBody2D, initially with CollisionShape2D.disabled = true, so it doesn't interact with anything. I want to find out if that disabled CollisionShape2D is overlapping with another CollisionShape2D (of a tile or of another KinematicBody2D). I need this as then I could postpone calling CollisionShape2D.disabled = false until it's safe to do so (i.e., it wont cause the physical engine to "teleport" the kinematic body out of the overlapping position, or the body stuck inside a wall).

What did I try so far: I have tried enabling the shape, then calling KinematicBody2D.test_move(from, rel_vec), then disabling it if that has returned true, But test_move didn't detect the overlap ifrel_vec is small (it should be 0 in my case anyway). Well, it's not a "move" what I want, so probably there's a better solution anyway. I also wanted to try get_world_2d().direct_space_state.collide_shape(...), but then the game has crashed, so I couldn't play around with that yet.

asked Apr 23, 2018 in Engine by hdc128 (12 points)

1 Answer

0 votes

Create a "dummy" CollisionShape2D in your code with exactly the same size and position as the one you are interested in. Then you can test that one. If it passes your test, you can free it, then turn back on collision for your actual CollisionShape2D.

answered Apr 23, 2018 by Diet Estus (1,390 points)
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.