how to set the position of a meshinstance using code

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

func _ready():
    var alphabet = letters.getAlphabet()

    for z in range(10):
	    for x in range(10):
		    var mesh = load(letters.getLetter(alphabet[randi()%33]))
		    var meshInstance = MeshInstance.new()
		    meshInstance.set_mesh(mesh)
		    meshInstance.position = Vector3(x * 3, 0, z * 3)
		    add_child(meshInstance)

function letters.getAlphabet give alphabet array
function letters.getLetter give link to letter file with .obj expansion

:bust_in_silhouette: Reply From: Bot7

You shouled use KinematicBodys because there are easier https://www.youtube.com/watch?v=rOA8i_clm1Y&t=297s

:bust_in_silhouette: Reply From: Wakatta

For Spatials such as meshinstance the “position” is reference using its transform
so change meshInstance.position to meshInstance.global_transform.origin

The correct way though is actually to use the translate() func like meshInstance.translate(Vector3(x * 3, 0, z * 3))

extends Spatial
 
func _ready():
var alphabet = letters.getAlphabet()
for z in range(10):
    for x in range(10):
        var mesh = load(letters.getLetter(alphabet[randi()%33]))
        var meshInstance = MeshInstance.new()
        meshInstance.set_mesh(mesh)
        meshInstance.global_transform.origin = Vector3(x * 3, 0, z * 3)
        add_child(meshInstance)