Godot Version
v4.6.stable.official
Question
I am making a game where static objects appear around the player. But even tho I have collision layers and masks set up correctly player still just phases thru the objects.
here is the spawning script
func spawn_point():
decide_random_values()
var entity = general_entity_instancer.get_spawn_object(GameProperties.current_entity_id).instantiate()
entity_holder.add_child(entity)
entity.rotation.y = rad_to_deg(randi_range(0,rand_rotation))
entity.scale = randomize_scale(random_scale_bottom,random_scale_top)
entity.set_global_position(randomize_position(range_limit_x,range_limit_z))
and here is the script that returns the objects
@export var tree: PackedScene
@export var dry_tree: PackedScene
func get_spawn_object(entity_id):
match entity_id:
"tree":
return tree
"dry_tree":
return dry_tree
The provided scripts contain no logic for collisions.
If you place the object by hand in the editor, can you collide with them? Than the scripts show no information.
We would need to know how the nodes in the scenes for player, tree and dry_tree are setup.
First step to find the issue could be to show collision shapes at runtime under Debug - Visible collision shapes.
When I put tree object in the scene it collides with player normally. And when I turn visible collision shapes on, the collider is visible on all the objects it just doesn’t react with the player on the spawned ones.
The way the scene is set up is by creating a grid of invisible “spawner objects” in ready function. These spawner objects then spawn a tree when the player is near.
ok, that is strange.
What is the range of random_scale_bottom and random_scale_top ?
That is the only thing that could be different to placing it by hand in the editor.
Do you have added the manual test tree to the entity_holder, too? Does the holder has extra settings that could alter the collision settings?
Ok I think I found the cause of the problem, the grid of spawner objects that is created at the start is too big. Even before i noticed that after certain grid size, spawner objects just stopped appearing. I was holding the grid size pretty near that object cap but it seems godot doesn’t like that because when I reduced the size of the grid the collision of spawned objects started working.
I will have to prevent this problem by implementing proper chunk system.
Just for reference this problem started appearing around 10230 objects that look like this
Still, thank you for replying
1 Like