Instantiate a 3d node at a particular position

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

Hi, I’m new at Godot,
I want to instantiate a node at some point in 3d using GDScript. I found examples about how to do that in 2d, but I cannot find a solution for 3d.

I put my code bellow to show what I’m traying to do. At code, Cube and CubeWater are StaticBody:

extends Spatial

var rng =

# Nature blocks
var Cube = preload("res://0Proves/ProceduralGeneration/Cube.tscn")
var CubeWater = preload("res://0Proves/ProceduralGeneration/CubeWater.tscn")

# Size of the world
var WorldSize : Array = [32, 32]
# Positions of the world, starts fixing x and varying z
var WorldPositions : Array = []

func _ready():
    for i in range(WorldPositions.size()):
	    WorldPositions[i] =  rng.randi_range(0,1)
	    # default tile: Cube
	    var nodeToAdd = Cube.instance()
	    if WorldPositions[i] == 0:
	    elif WorldPositions[i] == 1:
		    nodeToAdd = CubeWater.instance()
		    print("Something went wrong")
	    #nodeToAdd.position= Vector3(1,0,1) # I tried a random position
:bust_in_silhouette: Reply From: gamedevshirious

For 3D the property is called translation
You can use a Position3D node, place it exactly where you want
nodeToAdd.translation = $Position3D.translation

Hope this helps :slight_smile:

:bust_in_silhouette: Reply From: RoniPerson

In 3d it is

nodeToAdd.translation = Vector3(1,0,1)

You can see the real name for coding when you hover over a property in the editor.