Scatter instances

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zombieakopaluetze

Hello,

I’m very new to Godot and I am trying to figure out some basic stuff with GD-Script. I have a question on how to scatter geometry (trees or grass f.e) to positions. Here is what I have so far:

extends Spatial

export(PackedScene) var obj_scene 
#Refers to my instance mesh
    
func _ready():
	instance_meshes()

func instance_meshes():
	var new_obj = obj_scene.instance()
	add_child(new_obj)
	new_obj.translation = Vector3(2, 0, 0)

This adds an instance of my mesh at the given position (2,0,0). But how do you create a lot of positions and add a instance to every entry? Is there a clever way to generate many points/positions? I’m looking for something like:

  • Take this geometry (maybe a ground plane) and add random position on the surface.

If I could get an array of positions I could loop over them and add an instance to every position.

Thanks and sorry if this is something very basic, it’s all new for me. Any help, link or hint is very appreciated.