Collision doesn't work properly

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


I want to create a projectile that collides and hides itself on coliision.
For now, it just fiels trough the collision shape of the enemy entity, and Idk what to do.
As you can see from the screenshot, theres collsion shapes on both the projectile and the enemy. Idk why it shouldnt work ?

well you aren’t really telling us how you are detecting the collision and what are you doing with it after :slight_smile:

Nuno Donato | 2017-05-30 17:16


func _integrate_forces(state):
	print(state.get_contact_count())
	if state.get_contact_count() > 0:
		self.hide()

this is basically the code, I have not a single clue where the problem could originate from.
All the tutorials tell there only should be some collision shapes as child to the colliding objects.

astraf | 2017-05-30 17:20

:bust_in_silhouette: Reply From: Nuno Donato

that’s definitely not the way to do it. you should set up an area with a collision shape, and connect the body_enter signal to a function, in which we then check which body entered and decide what to do with it.

there are plenty of tutorials on this already, all kind of simple shooters implement this mechanic

can you give me a link, I have not seen antyhing like this

astraf | 2017-05-30 17:48

did you check godot’s own official demos? there’s a simple space shooter in there

Nuno Donato | 2017-05-30 17:54

:bust_in_silhouette: Reply From: lavaduder

There are a lot of ways to detect collision. I have never seen this method.

All I can say is get rid of this method and try this one.

  1. Put a area2d node inside your rigid body. Like so
    RigidBody2d
    —Collision2d (This is if you don’t want the object to go through objects)
    —Area2D
  2. Now select your Area2D, and go to your Node tab in the editor(It’s a tab in the same place as the inspector)

3.You should have signals loaded up. Under Area2D signals there is body_enter( Object area )
Double Click on it.

4.You will get a pop up window, with “please confirm…” select your RigidBody2D
Then at the bottom of the pop up window press connect.

5.Now you should have a body_enter( Object area ) inside your RigidBody2D script.
This is where you can preform your collision functions.

Also for future reference you can have a body_exit( Object area ) in case you want a function to continue until you leave a object’s collision.