I looked up this method, but for the life of me I can't seem to get it to work even though I'm fairly sure it's adding correctly. In order to prevent silly pathfinding problems with my agents I'm experimenting with using collision_exception to have them no clip through each other when they're gathering resources. Problem though, the collision still works, is there something extra I'm missing? Or is it that my code is not keeping track of things properly somewhere? I'm making use of the on_child_entered signal with a manager to track the agents when they're created so there's no silliness with it constantly executing, I then do a for loop and have each agent add the collision exception of the agent in the list.

var miningRigs = []

func _on_child_entered_tree(node):
	for miningRig in miningRigs:
		miningRig.add_collision_exception_with(miningRig)
func SpawnMiningRig():
	miningRigInstance = miningRig.instantiate()
	miningRigManager.add_child(miningRigInstance)
	miningRigInstance.global_transform.origin = minerSpawnLocation.global_transform.origin

Pesudo code, would've though this would be fine but apparently not lol, let me know if you want more details on the project or screenshots.

  • xyz replied to this.
  • Lethn miningRig in your loop code is an iterator. Regardless of what actual object it's referring to, you're adding an exception for that object with itself. You're doing this:

    for A in some_array:
    	A.dont_collide_with(A)

    Which at best accomplishes nothing.

    Lethn changed the title to Add_Collision_Exception_With not disabling collision for bodies? .

    Lethn

    miningRig.add_collision_exception_with(miningRig)

    ^ You're adding an exception with itself, which doesn't make much sense.

      xyz The mining rig in the for loop is a node that gets added as a new child instance every time the spawn function is called and the new mining rigs add themselves to the mining rig array when they're added as children of the MiningRigManager. Unless my brain has completely blanked on something which I suspect it has surely this should work right? I want the collision exceptions to happen across all mining rigs so they never collide with each other is what I was thinking.

      • xyz replied to this.

        Lethn miningRig in your loop code is an iterator. Regardless of what actual object it's referring to, you're adding an exception for that object with itself. You're doing this:

        for A in some_array:
        	A.dont_collide_with(A)

        Which at best accomplishes nothing.

        That's annoying, I should be using a group or something else then shouldn't I and grabbing references differently? Then having the exception update itself every time a new mining rig is made, thanks, will be able to solve it now no problem.

        Just for the sake of making sure this is a complete thread, there is in fact zero need to use add_collision_exception_with() when implementing my idea. There were two problems I hilariously came across that I had not realised at all.

        . My avoidance radius for the agents was set far too high so that meant it looked like they were bumping into each other when they actually weren't they were trying to calculate paths around each other

        . You can turn off the layer for the scene instance you're adding into the game and that will prevent any actual collision from happening with each other without the need for code, I was overcomplicating things, have them on a separate layer with everything else and collisions will happen normally for that, keep mask for Area detection etc.

        What an absolute facepalm moment, but at least I fixed it, got the idea from reading up on collision masks/layers in general and people mentioned bullets, same principle can work fine with my mining rigs, may have to do some redesigning of my refineries now I've solved this annoying problem 🙂