Godot Version
4.4.1
Question
Hi,
I am trying to create a spawn area that will spawn lots of a scene onto the ground below it.
I have got a functioning area (collision shape) as the scene that randomly spawns multiples of another scene (collision and mesh).
I just cannot find a way to have the instantiated scene be placed on the ground below it. I was mostly trying to find a way to get a y position that is on the surface of the ground.
Here is what I have for the spawn area (from a tutorial on Youtube)
extends Area3D
var spawn_opject = preload("res://scenes/resourceAtomA.tscn")
var spawn_number = 10
var random = RandomNumberGenerator.new()
func _ready():
spawn()
func getRandomPos(size) -> Vector3:
random.randomize()
var x = random.randf_range(-abs(size/2),abs(size/2))
var z = random.randf_range(-abs(size/2),abs(size/2))
var y = 1 ##### I need this to equal the surface of the mesh below #####
# $MeshInstance3D/StaticBody3D/terrainCollision3D
return Vector3(x,y,z)
func spawn():
for i in spawn_number:
var obj = spawn_opject.instantiate()
obj.position = getRandomPos(50)
add_child(obj)
Would using raycast work? If so how would I do that?