object's contact collision doesn't report properly when it collides with another object

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

Hey everyone. I have this collision problem that every time an enemy hits a projectile, it doesn’t register in the contacts reported. Below is the code from my projectile script and enemy script. Thank you in advance and I’d appreciate every help that I could get. Cheers!

from projectile script

func _integrate_forces(s):
 bullet_contact = s.get_contact_count()
 if(bullet_contact >=1):
	queue_free()

from enemy script

	for y in range (s.get_contact_count()):
	#print ("count: "+str(s.get_contact_count()))
	 if (s.get_contact_count()>1):
		var cc = get_colliding_bodies()
		print ("number of colliding bodies: "+str(cc))
		if (cc.size()>1):
			#print(cc[y].get_name())
			if (cc[y].get_name() == "Portal"):
				#print("cc[y].get_name(): "+str(cc[y].get_name()))
				queue_free()
			if (cc[y].get_name() == "projectile"):
				#print("cc[y].get_name(): "+str(cc[y].get_name()))
				print ("bullet: "+str(cc[y].get_name()))
				queue_free()

First thing to check. Do you have the Contacts Reported set higher than 0?

avencherus | 2017-03-12 10:32

Hi Avencherus. Yup I did. My problem appears when I queue_free projectile upon collision but when I remove queue free it does register in the enemy’s contact reporting.

ddarkmoto | 2017-03-12 10:37

It would be a bit of work, but you intent on this arrangement, then you will want to print out the references of these objects during the frames in question. Just to see when they are no longer available.

Queue free cleans it up on the next frame, but I don’t know exactly how the internals treat this inside the physics step. It may be flagged and ignored. Someone with deeper knowledge there could probably give a better answer.

The other way to go is to do contact logic in the projectile, and if you identify a certain type, call a function.

Pseudo code as:

if(hit_target == player):
  player.hit_by_bullet()

queue_free()

avencherus | 2017-03-12 10:48