Why medium asteroids collide with each other and collide with large asteroids

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

Why medium asteroids collide with each other and collide with large asteroids. How to fix it?
project link: https://drive.google.com/file/d/1oi-RtxDYRX2HfA1ldVFzxIo4EHmlwQ59/view?usp=sharing

:bust_in_silhouette: Reply From: Bernard Cloutier

When you create an asteroid, you add it as a child of the asteroid spawner node. The asteroid spawner node is on layer 1, and so all asteroids (and the player) will collide.

Simply change the node type of the asteroid_spawner to a Node2D instead of a KinematicBody2D, since Node2D doesn’t have collision layers and won’t interfere with the child asteroids.

they collide anyway

Timofey | 2020-10-01 11:59

Oh, sorry, I thought the asteroids were added as childs of asteroid_spawner but now I see you add them to the spawner’s parent.

But I’ve found your problem, it’s pretty weird. For some reason, the middle asteroid is colliding with big asteroid (not the small ones weirdly). I opened middle_asteroid.tscn and big_asteroid.tscn in notepad++ and found that they had garbage values in place of collision masks and collision layers. To fix your issue, close godot, open those two files, go to the bottom and make sure you have collision_layer = 6, and remove the line collision_mask = ...

I don’t know how they ended up with garbage values though.

Bernard Cloutier | 2020-10-01 14:44

thanks, now everything works.

Timofey | 2020-10-01 16:19