Hello !
In my game i have many differents mechanics. To make thoses mechanics starts i need to detect when my character touched/entered a mesh. What i’m looking for is the best way to handle thoses events, especially for performance.
I have thinked about 3 ways :
1 - Put an Area 3D in all the mechanics, so i would have 100+ area 3D in my game. Then create an event associed to theses mechanics.
2 - Put an Area 3D only on my character. But the events would be triggered in many scripts and in each event i would need to check in all theses scripts if the area entered correspond the script mechanic.
3 - Put a Shapecast 3D on my character. But i would need to check in each frame in all my scripts if the Shapecast collided meshs correspond to the script mechanic.
So what would be the best solution in your opinion ? Thank you
If the functions are called on the “mechanic” node, I would go with option 1, as you can do all the code within that node without coupling it to the player node.
But options 2 and 3 are not necessarily bad either, all should work fine. I would maybe use a Raycast instead of Shapecast, but maybe you have a good reason to use Shapecast.
Option 2 and 3 are still going to need 100+ collision shapes on the mechanic options to detect a collision. Areas will be preferable if you do not intend to detect and stop collisions like a RigidBody or CharacterBody is built to do.
If you are specifically worried about performance issues then you can make use of strict collision masks/layers to only detect player and mechanic collisions, along with setting only one of the Monitorable or Monitoring properties.