My second question. In my 3d rpg game, I am creating a prototype where you have two knights and a bunch of randomly placed hounds in a room.
I have created an Area node in the main scene that will be the area where the randomly created hounds will appear.
In a script attached to the main scene, loop 6 times and create hound instances off of my hound scene and add then as CHILDs to the Area node. I do this because it is, at least in my opinion, cleaner to generate random x and z positions for grounded enemies by simply using the range -1,1 for the x and z coordinates. These are taken as local coordinates within the area so works nicely. Each hounds spawn function is nicely contained within an enemy.gd script attached to each Hound scene.
Because the hounds are children of this area that I created and this is scalled, I reset all of the hounds scale by mutliplying it with 1/Area.scale.x, 1/Area.scale.y and 1/Area.scale.z (found this useful trick out in another Godot forum)
In order to detect whether a hound has landed on another hound while being randomly placed, I have each hound have an Area node of its own that is roughly the same size as its collision shape. In the physicsprocess(delta)() function of the hound, I have this check to see if it is spawned on another area:
var spawned = false
var bodies = $Area.get_overlapping_areas()
if(bodies.size()):# and !spawned):
spawned = true
var x_pos = rand_range(-1,1)
var z_pos = rand_range(-1,1)
This means, if the hounds did land on each other, for a split second when the level loads up, I see a hound or two quickly change positions before settling down.
The main level scene script takes care of spawning all hounds and when all hounds have their spawned flag set to true, it will stop spawning and move on to other processing and not call the spawning process again.
It does appear to be quite a round about way of accomplishing something trivial. Is there a more effecient way of detecting collisions straight away of a spawned object? (without calculating the bounds of each spawned enemy already and comparing it with this list)