0 votes

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

in Engine by (159 points)

1 Answer

+1 vote
Best answer

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.

by (1,246 points)
selected by

they collide anyway

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.

thanks, now everything works.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.