so there is code for now to figure out where sphere is on grid
grid_position = Vector3i(sphere_node.global_position / TILE_SIZE)
var below = grid_position + Vector3i(0, -1, 0)
print("Cell standing on: ", below, grid_map.get_cell_item(below))
movement itself is done by check of if there is next cell to move on , if so move_to_next_cell is executed
if Input.is_action_just_pressed("forward"):
print("is there next cell?", is_there_next_cell())
if is_there_next_cell():
move_to_next_cell()
for where_is_forward is used help of Claude as I couldn’t figure out how to get Projection
func where_is_forward() -> Vector3:
var forward = camera_3d.global_basis * Vector3.FORWARD
forward -= current_normal * forward.dot(current_normal)
forward = forward.normalized()
return forward
for check of next_cell used direction( Claude version for now ) , added grid_position and checked Y -1 ( that where its instantiated ), return only valid cells with occupied items
func is_there_next_cell() -> bool:
var direction = where_is_forward()
var next = grid_position + Vector3i(direction)
var top_face = next + Vector3i(0, -1, 0)
print("direction: ", direction, " next: ", next, " top_face ", top_face)
return grid_map.get_cell_item(top_face) != GridMap.INVALID_CELL_ITEM
hardcoded move by size 1 as this is standard measure for cube in project
func move_to_next_cell() -> void:
var direction = where_is_forward()
grid_position += Vector3i(direction)
sphere_node.position += direction * TILE_SIZE
Some ideas how to improve the logic for this Projection from camera ?