extends Node3D
@onready var grid_map: GridMap = $"../GridMap"
var cell_world_positions: Array[Vector3] = []
@onready var grid_position_player = 0
@onready var start_pos = global_position
func _ready() -> void:
var used_cells = grid_map.get_used_cells()
print(used_cells)
for cell_index in used_cells:
var world_pos = grid_map.map_to_local(cell_index)
print(world_pos, cell_index)
var absolute_pos = grid_map.to_global(world_pos)
print(absolute_pos, world_pos)
cell_world_positions.append(absolute_pos)
print("player position", global_position)
print(cell_world_positions[0])
func _process(delta: float) -> void:
if Input.is_action_just_pressed("forward"):
grid_position_player +=1
if grid_position_player <= 12:
print(grid_position_player)
global_position = cell_world_positions[grid_position_player] + Vector3(0, 1.663997, 0) - Vector3(0, 0.5, 0)
else:
pass
I came with this ( for now array size is hardcoded , I look into tweens at evening ) . Many thanks for help with it .
Is there a better approach then using for loop for translation of cells into world positions ?
current output
Godot Engine v4.6.stable.custom_build - https://godotengine.org
Metal 3.2 - Forward+ - Using Device #0: Apple - Apple M2 Max (Apple8)
[(-1, 0, 0), (-2, 0, 0), (-3, 0, 0), (-4, 0, 0), (-5, 0, 0), (-6, 0, 0), (-7, 0, 0), (-7, 0, -1), (-7, 0, -2), (-7, 0, -3), (-8, 0, -3), (-9, 0, -3), (-10, 0, -3)]
(-0.5, 0.5, 0.5)(-1, 0, 0)
(-0.5, 0.5, 0.5)(-0.5, 0.5, 0.5)
(-1.5, 0.5, 0.5)(-2, 0, 0)
(-1.5, 0.5, 0.5)(-1.5, 0.5, 0.5)
(-2.5, 0.5, 0.5)(-3, 0, 0)
(-2.5, 0.5, 0.5)(-2.5, 0.5, 0.5)
(-3.5, 0.5, 0.5)(-4, 0, 0)
(-3.5, 0.5, 0.5)(-3.5, 0.5, 0.5)
(-4.5, 0.5, 0.5)(-5, 0, 0)
(-4.5, 0.5, 0.5)(-4.5, 0.5, 0.5)
(-5.5, 0.5, 0.5)(-6, 0, 0)
(-5.5, 0.5, 0.5)(-5.5, 0.5, 0.5)
(-6.5, 0.5, 0.5)(-7, 0, 0)
(-6.5, 0.5, 0.5)(-6.5, 0.5, 0.5)
(-6.5, 0.5, -0.5)(-7, 0, -1)
(-6.5, 0.5, -0.5)(-6.5, 0.5, -0.5)
(-6.5, 0.5, -1.5)(-7, 0, -2)
(-6.5, 0.5, -1.5)(-6.5, 0.5, -1.5)
(-6.5, 0.5, -2.5)(-7, 0, -3)
(-6.5, 0.5, -2.5)(-6.5, 0.5, -2.5)
(-7.5, 0.5, -2.5)(-8, 0, -3)
(-7.5, 0.5, -2.5)(-7.5, 0.5, -2.5)
(-8.5, 0.5, -2.5)(-9, 0, -3)
(-8.5, 0.5, -2.5)(-8.5, 0.5, -2.5)
(-9.5, 0.5, -2.5)(-10, 0, -3)
(-9.5, 0.5, -2.5)(-9.5, 0.5, -2.5)
player position(-0.448021, 1.663997, 0.548285)
(-0.5, 0.5, 0.5)
1
2
3
4
5
6
7
8
9
10
11
12