The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi,
I'm testing a random walk algorithm, it seems to be correct, but when I try to test it instanciating tiles, things go wrong. The game world is made of squared tiles, let's say 5x5 for testing:

[(-2, 0, -2), (-2, 0, -1), (-2, 0, 0), (-2, 0, 1), (-2, 0, 2), (-1, 0, -2), (-1, 0, -1), (-1, 0, 0), (-1, 0, 1), (-1, 0, 2), (0, 0, -2), (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 0, 2), (1, 0, -2), (1, 0, -1), (1, 0, 0), (1, 0, 1), (1, 0, 2), (2, 0, -2), (2, 0, -1), (2, 0, 0), (2, 0, 1), (2, 0, 2)]

A random walk of size 5 tiles has the following translations:

[(0, 0, 0), (-1, 0, 0), (-1, 0, -1), (-2, 0, -1), (-2, 0, -2)]

To see the result, I try to erase this translations from the previous array:

func erase_array_from_array(array : Array, erase : Array) -> Array:
    array = array.duplicate()
    for i in range(erase.size()):
        array.erase(erase[i])
    return array

So the tiles translations are:

[(-2, 0, 0), (-2, 0, 1), (-2, 0, 2), (-1, 0, -2), (-1, 0, 1), (-1, 0, 2), (0, 0, -2), (0, 0, -1), (0, 0, 1), (0, 0, 2), (1, 0, -2), (1, 0, -1), (1, 0, 0), (1, 0, 1), (1, 0, 2), (2, 0, -2), (2, 0, -1), (2, 0, 0), (2, 0, 1), (2, 0, 2)]

This seems to work. The problem is when instanciating the tiles:

var tile : Spatial
for i in range(tilesTranslations.size()):
    tile = ASSETS3.EmptyTile.instance()
    tile.translation = tilesTranslations[i]
    add_child(tile)

And the result is:
enter image description here

Obviously, the result is wrong, since the tile at (0, 0, 0) shoudn't exists.

Full part of the code:

var tilesTranslations : Array = _generate_tiles_translations()

var walk = SECTOR_FUNCS.random_walk2(5, Vector3.ZERO, tilesTranslations)

print(tilesTranslations)
tilesTranslations = GEN_FUNCS.erase_array_from_array(tilesTranslations, walk)
print(tilesTranslations)
print(walk)


var tile : Spatial
for i in range(tilesTranslations.size()):
    tile = ASSETS3.EmptyTile.instance()
    tile.translation = tilesTranslations[i]
    add_child(tile)
Godot version 3.3.3
in Engine by (255 points)

Are you sure ASSETS3.EmptyTile only contains one tile? It is rather odd that on a designated 5x5 grid you get 6x6 tiles.

Oh, I didn't noticed! I checked in the past but it seems I changed something. Now it is fixed and everithing works!

Please log in or register to answer this question.

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.