Godot Version 4.3
I have 1 main object and eight instances and I want the main object know know witch specific instance it is touching.
I know that I could use a singleton to let the main object know but I was wondering if instead I could have each instance have a different collision mask and the main object be on each of those layers.
The one part of this that I don’t know how to do is let the main object when it touches layer 3? layer 5? ect.
Is this possible?
There will always be eight instances and they don’t need to be instances so is it better to make them normal nodes?
Is it better to just use a singleton?
No Singleton needed, the physics engine is built for this. And i would say there are more simple ways to do this, but you are almost there.
For your 8 instances you can name them and on collision check the name. Or add a special export value and check the property on collision. A static value that increments for each instance. You could check the collision layer the body is assigned too. Or you could have 8 areas each assigned to one layer and have custom code for each body enter signal. There is also meta data, groups, and probably many other ways to identify an instance…
Any way just setup a collision callback and check the data on the object you collide with during the signal.
4 Likes
Thank You this led me to go down a loop hole about collision and I learned a lot and got it working.
Checking by the name might not be very preformative. I usually just check by the layer number instead. The only downside to that is the code isnt very readable.
1 Like