0 votes
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

Godot version 3.2.2.stable.official
in Engine by (155 points)
edited by

2 Answers

+1 vote
Best answer

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)
by (5,808 points)
selected by
+1 vote

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

by (257 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.