How do I get a collision going?

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

I’m trying to set a collision, I’ll try to be as clear as possible.

As of now I have my character, moves in 4 directions, and I have an β€œenemy” that goes up and down in the level.

β—˜ β—‹β—‹β—‹β—‹β—‹β—‹β—‹ ↑ β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹ β—˜
β—˜ β—‹β—‹β—‹β—‹β—‹β—‹β—‹ En β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹ β—˜
β—˜ β—‹β—‹β—‹β—‹β—‹β—‹β—‹ ↓ β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹ β—˜
β—˜ β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹β—‹ Char β—‹β—‹β—‹ β—˜

Both Kinematics 2D, with direct child CollisionShape. Now I want to say (the script is in the character):

β€œif (my collisionshape overlaps with another collisionshape) do something”

That β€œdo something” would be relocating my character, that part is handled. But I’m having problems getting the collision. So far I haven’t been able to use β€œis_colliding” properly.

Thanks in advance.


Do you have set_contact_monitor(true) and set_max_contacts_reported(>0) ? it’s a common problem :slight_smile:

Nutr1z | 2017-01-21 08:58

:bust_in_silhouette: Reply From: eons

The node CollisionShape2D is only an editor helper to make drawing shape resources more easy, it won’t report anything by itself.

If you want to detect collisions with a KinematicBody, you need to use the method move followed by is_colliding and other methods that give you collision information.

Read the official tutorials about KinematicBody2D

And look at both demos, the one of Kinematic Collision (basic) and Kinematic Character (more advanced).