error when detecting collisions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Player_0

Hello, my error is that I have a scene with its respective script that fulfills the bullet function and I have another scene with its respective player script, instance and I create the bullet in the player, until there everything works perfectly, the bullet is It is moving thanks to the function move_and_collide (), taking into account that the bullet is always in motion, when the two bodies collide the player and the bullet, it only works when it collides head-on, but if the player collides with the bullet from behind it not detects the collision.

If I was not very clear tell me to clarify it specifically

My code


func _muerte_por_colision() -> void:
if  colision.collider.is_in_group("players"):  
	Singleton.emit_signal("death", colision.collider)
elif colision.collider.is_in_group("proyectil"):
	movimiento = movimiento.bounce(colision.normal)               
	alt = false

func _physics_process(delta):

if colision:
	print(colision, "se activo")

if alt == true:
	movimiento = Vector2(4,0).rotated(rotation)       
	colision = move_and_collide(movimiento)           
	colision = move_and_collide(movimiento)          

count += delta                                
if count > 16:


if municion > 0:
				var bala = Singleton.BALA.instance()
				get_parent().call_deferred("add_child", bala)
				bala.position = get_node("Core/salida").global_position
				bala.rotation_degrees = $Core.global_rotation_degrees
				municion -= 1

Check your layer and mask if it is right

Mrpaolosarino | 2021-04-01 13:06

yep i do and it is right

Player_0 | 2021-04-01 13:11

:bust_in_silhouette: Reply From: Firty

I used to use area2D to detect collisions, it is much simpler. Use an area2D on the bullet and another on your targets. When one area invades another, the target takes damage and the bullet causes it to be destroyed. I haven’t played in a while, but if I’m not mistaken, area2d even has a name check, that is, you can check the name of the node you invaded.

yes the solution that you say is good, but i has that update all the code for the move of my bullets and that is complicated, that can produce new errors :'c anyways thanks for your answer

Player_0 | 2021-04-01 22:40