2022-08-25 15:33:44 +02:00
|
|
|
extends Spatial
|
|
|
|
|
2022-08-25 17:06:26 +02:00
|
|
|
onready var fps_label = $CanvasLayer/HBoxContainer/FPSLabel
|
|
|
|
onready var player_pos_label = $CanvasLayer/HBoxContainer/PlayerPos
|
2022-08-25 23:40:19 +02:00
|
|
|
onready var tile_pos_label = $CanvasLayer/HBoxContainer/TilePos
|
2022-09-15 12:32:45 +02:00
|
|
|
onready var Island = preload("res://scenes/Island.gd")
|
2022-08-25 17:06:26 +02:00
|
|
|
onready var player = $Player
|
2022-09-15 12:32:45 +02:00
|
|
|
onready var world = $World
|
2022-08-25 17:06:26 +02:00
|
|
|
|
|
|
|
var player_velocity = Vector3.ZERO
|
2022-08-31 16:43:15 +02:00
|
|
|
var player_speed = 5
|
2022-08-25 17:06:26 +02:00
|
|
|
var target_coordinate = Vector3.ZERO
|
2022-08-25 15:33:44 +02:00
|
|
|
|
|
|
|
func _ready():
|
2022-09-15 12:32:45 +02:00
|
|
|
for node in world.get_children():
|
|
|
|
if node is Island:
|
|
|
|
node.generate()
|
|
|
|
node.connect("island_tile_selected", self, "on_island_tile_selected")
|
|
|
|
node.connect("island_tile_hover", self, "on_island_tile_hover")
|
2022-08-25 17:06:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
fps_label.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS))
|
|
|
|
player_pos_label.text = "Pos: " + str(player.transform.origin)
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
var position_error = target_coordinate - player.transform.origin
|
|
|
|
var error_length = position_error.length()
|
|
|
|
|
2022-09-15 12:32:45 +02:00
|
|
|
if error_length > 0.05:
|
2022-08-25 17:06:26 +02:00
|
|
|
player_velocity = position_error / error_length * player_speed
|
|
|
|
else:
|
|
|
|
player_velocity = Vector3.ZERO
|
|
|
|
|
|
|
|
player.transform.origin += player_velocity * delta
|
|
|
|
|
|
|
|
|
2022-09-15 12:32:45 +02:00
|
|
|
func on_island_tile_selected(island, tile):
|
|
|
|
target_coordinate = tile.global_transform.origin
|
2022-08-25 17:06:26 +02:00
|
|
|
var position_error = target_coordinate - player.transform.origin
|
2022-09-15 12:32:45 +02:00
|
|
|
print ("clicked on tile " + str(target_coordinate) + " error: " + str(position_error))
|
2022-08-25 17:06:26 +02:00
|
|
|
|
2022-08-25 23:40:19 +02:00
|
|
|
|
2022-09-15 12:32:45 +02:00
|
|
|
func on_island_tile_hover(island, tile):
|
|
|
|
tile_pos_label.text = "TilePos: " + str(tile.global_transform.origin)
|