Réparation des déplacements

pull/19/head
Valentin Stark 3 years ago
parent 74a75b6193
commit 09986a63f5
  1. 2
      .godot/editor/3DWorld.tscn-folding-5ee7dca069a2497be3bb28c4d56856bf.cfg
  2. 8
      .godot/editor/Instance.tscn-editstate-9d991e3bcaa18250a5137d16090bc9f4.cfg
  3. 2
      .godot/editor/Instance.tscn-folding-9d991e3bcaa18250a5137d16090bc9f4.cfg
  4. 1
      .godot/editor/create_recent.Node
  5. 34
      .godot/editor/filesystem_cache8
  6. 10
      .godot/editor/filesystem_update4
  7. 40
      .godot/editor/script_editor_cache.cfg
  8. 2
      scenes/3DWorld.tscn
  9. 10
      scenes/Instance.tscn
  10. 89
      scripts/Entity.gd
  11. 15
      scripts/Instance3D.gd
  12. 6
      scripts/Selection.gd
  13. 2
      scripts/World.gd

@ -1,5 +1,5 @@
[folding] [folding]
node_unfolds=[NodePath("Grid"), PackedStringArray("Transform", "Cell", "Navigation"), NodePath("WorldEnvironment"), PackedStringArray("environment"), NodePath("Ocean/Mesh"), PackedStringArray("Transform", "Skeleton", "mesh"), NodePath("Ocean/CollisionShape3D"), PackedStringArray("shape"), NodePath("DirectionalLight3D"), PackedStringArray("Transform", "Light", "Shadow", "Directional Shadow"), NodePath("Highlighter"), PackedStringArray("Transform"), NodePath("Camera3D"), PackedStringArray("Transform")] node_unfolds=[NodePath("Grid"), PackedStringArray("Transform", "Cell", "Navigation", "Collision"), NodePath("WorldEnvironment"), PackedStringArray("environment"), NodePath("Ocean"), PackedStringArray("Collision"), NodePath("Ocean/Mesh"), PackedStringArray("Transform", "Skeleton", "mesh"), NodePath("Ocean/CollisionShape3D"), PackedStringArray("shape"), NodePath("DirectionalLight3D"), PackedStringArray("Transform", "Light", "Shadow", "Directional Shadow"), NodePath("Highlighter"), PackedStringArray("Transform"), NodePath("Camera3D"), PackedStringArray("Transform")]
resource_unfolds=["res://scenes/3DWorld.tscn::PlaneMesh_7x62x", PackedStringArray("Resource"), "res://scenes/3DWorld.tscn::BoxShape3D_g3t7x", PackedStringArray()] resource_unfolds=["res://scenes/3DWorld.tscn::PlaneMesh_7x62x", PackedStringArray("Resource"), "res://scenes/3DWorld.tscn::BoxShape3D_g3t7x", PackedStringArray()]
nodes_folded=[] nodes_folded=[]

@ -97,19 +97,19 @@ Anim={
"auto_orthogonal_enabled": true, "auto_orthogonal_enabled": true,
"cinematic_preview": false, "cinematic_preview": false,
"display_mode": 20, "display_mode": 20,
"distance": 3.42936, "distance": 34.5087,
"doppler": false, "doppler": false,
"frame_time": false, "frame_time": false,
"gizmos": true, "gizmos": true,
"half_res": false, "half_res": false,
"information": false, "information": false,
"listener": true, "listener": true,
"position": Vector3(0, 0, 0), "position": Vector3(0.524021, 1.30454, 0.921615),
"use_environment": false, "use_environment": false,
"use_orthogonal": false, "use_orthogonal": false,
"view_type": 0, "view_type": 0,
"x_rotation": 0.5, "x_rotation": 0.312378,
"y_rotation": -0.5 "y_rotation": -8.91249
}, { }, {
"auto_orthogonal": false, "auto_orthogonal": false,
"auto_orthogonal_enabled": true, "auto_orthogonal_enabled": true,

@ -1,5 +1,5 @@
[folding] [folding]
node_unfolds=[NodePath("Pivot/MeshInstance3D"), PackedStringArray("Skeleton")] node_unfolds=[NodePath("Pivot"), PackedStringArray("Transform"), NodePath("Pivot/MeshInstance3D"), PackedStringArray("Skeleton", "mesh"), NodePath("CollisionShape3D"), PackedStringArray("shape", "Transform"), NodePath("RayCast3D"), PackedStringArray("Transform", "Collide With")]
resource_unfolds=["res://scenes/Instance.tscn::CapsuleMesh_qsbqh", PackedStringArray(), "res://scenes/Instance.tscn::CapsuleShape3D_ed37x", PackedStringArray()] resource_unfolds=["res://scenes/Instance.tscn::CapsuleMesh_qsbqh", PackedStringArray(), "res://scenes/Instance.tscn::CapsuleShape3D_ed37x", PackedStringArray()]
nodes_folded=[] nodes_folded=[]

@ -1,3 +1,4 @@
RayCast3D
Node3D Node3D
StaticBody3D StaticBody3D
CollisionShape3D CollisionShape3D

@ -1,12 +1,12 @@
2a60927148abd1d33b818b535e306557 2a60927148abd1d33b818b535e306557
::res://::1678647327 ::res://::1679346527
export_presets.cfg::TextFile::-1::1677194603::0::1::::<><>:: export_presets.cfg::TextFile::-1::1677194603::0::1::::<><>::
icon.png::CompressedTexture2D::4672001524465425285::1676578483::1676582905::1::::<><>:: icon.png::CompressedTexture2D::4672001524465425285::1676578483::1676582905::1::::<><>::
README.md::TextFile::-1::1676578483::0::1::::<><>:: README.md::TextFile::-1::1676578483::0::1::::<><>::
::res://assets/::1678647181 ::res://assets/::1679340435
environment.tres::Environment::8600195688495287911::1678647181::0::1::::<><>:: environment.tres::Environment::8600195688495287911::1679340435::0::1::::<><>::
water.gdshader::Shader::-1::1677174532::0::1::::<><>:: water.gdshader::Shader::-1::1677174532::0::1::::<><>::
::res://assets/blocs/::1678647181 ::res://assets/blocs/::1679341560
0_sides.glb::PackedScene::7036506600244808940::1677174532::1677174532::1::::<><>:: 0_sides.glb::PackedScene::7036506600244808940::1677174532::1677174532::1::::<><>::
0_sides_grass.png::CompressedTexture2D::4551055068461159203::1677174532::1677174532::1::::<><>:: 0_sides_grass.png::CompressedTexture2D::4551055068461159203::1677174532::1677174532::1::::<><>::
1_side.glb::PackedScene::5601417408597394875::1677174532::1677617210::1::::<><>:: 1_side.glb::PackedScene::5601417408597394875::1677174532::1677617210::1::::<><>::
@ -20,7 +20,7 @@ water.gdshader::Shader::-1::1677174532::0::1::::<><>::
4_sides.glb::PackedScene::139420628202576697::1677174532::1677174532::1::::<><>:: 4_sides.glb::PackedScene::139420628202576697::1677174532::1677174532::1::::<><>::
4_sides_grass.png::CompressedTexture2D::7961782411803042998::1677174532::1677174532::1::::<><>:: 4_sides_grass.png::CompressedTexture2D::7961782411803042998::1677174532::1677174532::1::::<><>::
blocs.meshlib::MeshLibrary::3161916306234183153::1677617602::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u blocs.meshlib::MeshLibrary::3161916306234183153::1677617602::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u
blocs.tscn::PackedScene::3779811605783367088::1678647181::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u blocs.tscn::PackedScene::3779811605783367088::1679341560::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u
::res://assets/images/::1677174532 ::res://assets/images/::1677174532
colors.png::CompressedTexture2D::2558953172502239658::1677174532::1677174532::1::::<><>:: colors.png::CompressedTexture2D::2558953172502239658::1677174532::1677174532::1::::<><>::
grass_top.png::CompressedTexture2D::3263707750932711970::1677174532::1677174532::1::::<><>:: grass_top.png::CompressedTexture2D::3263707750932711970::1677174532::1677174532::1::::<><>::
@ -55,19 +55,19 @@ sdqs.meshlib::MeshLibrary::2440886030015449773::1677616939::0::1::::<><>::uid://
blocs.meshlib::MeshLibrary::5001218139483850589::1677702801::0::1::::<><>::uid://ffn1ia7c3x60<>uid://birlu82nfgbsx<>uid://t03cipsdfuim<>uid://68inkwq5fe2v<>uid://blv0o0tit1gob<>uid://dg3l2dsc7n6s<>uid://dpewuerjdlgms<>uid://d3a4ur67k13wa<>uid://d1ioc5uj71iud<>uid://2s6bm46h6kfw<>uid://bttpxki4m82q1<>uid://bh7awq00jlfkn blocs.meshlib::MeshLibrary::5001218139483850589::1677702801::0::1::::<><>::uid://ffn1ia7c3x60<>uid://birlu82nfgbsx<>uid://t03cipsdfuim<>uid://68inkwq5fe2v<>uid://blv0o0tit1gob<>uid://dg3l2dsc7n6s<>uid://dpewuerjdlgms<>uid://d3a4ur67k13wa<>uid://d1ioc5uj71iud<>uid://2s6bm46h6kfw<>uid://bttpxki4m82q1<>uid://bh7awq00jlfkn
::res://assets/ui/::1677619095 ::res://assets/ui/::1677619095
bloc_select.png::CompressedTexture2D::1141775147858261351::1677618805::1677619095::1::::<><>:: bloc_select.png::CompressedTexture2D::1141775147858261351::1677618805::1677619095::1::::<><>::
::res://scenes/::1678647319 ::res://scenes/::1679341560
3DWorld.tscn::PackedScene::3599411568061770725::1678647181::0::1::::<><>::uid://blbwkgls3oafx<>res://scripts/Chunks.gd<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr<>uid://qjc4ttmkxbch<>res://scripts/Selection.gd 3DWorld.tscn::PackedScene::3599411568061770725::1679341559::0::1::::<><>::uid://blbwkgls3oafx<>res://scripts/Chunks.gd<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr<>uid://qjc4ttmkxbch<>res://scripts/Selection.gd
Game.tscn::PackedScene::9075056520838281688::1677174532::0::1::::<><>::uid://brjt1u0dgbmi4<>uid://d1sd7pxywgunu Game.tscn::PackedScene::9075056520838281688::1677174532::0::1::::<><>::uid://brjt1u0dgbmi4<>uid://d1sd7pxywgunu
HUD.tscn::PackedScene::9021570906125339886::1678647319::0::1::::<><>::res://scripts/Map.gd HUD.tscn::PackedScene::9021570906125339886::1679341560::0::1::::<><>::res://scripts/Map.gd
Instance.tscn::PackedScene::4220804716574195494::1678647181::0::1::::<><>::res://scripts/Instance3D.gd Instance.tscn::PackedScene::4220804716574195494::1679341560::0::1::::<><>::res://scripts/Instance3D.gd
WorldGeneration.tscn::PackedScene::1108513713840477990::1678647181::0::1::::<><>::res://scripts/WorldGeneration.gd WorldGeneration.tscn::PackedScene::1108513713840477990::1679341559::0::1::::<><>::res://scripts/WorldGeneration.gd
::res://scripts/::1678647319 ::res://scripts/::1679341493
Camera3D.gd::GDScript::-1::1677174532::0::1::::<>Camera3D<>:: Camera3D.gd::GDScript::-1::1677174532::0::1::::<>Camera3D<>::
Chunks.gd::GDScript::-1::1678219623::0::1::::<>GridMap<>:: Chunks.gd::GDScript::-1::1678662538::0::1::::<>GridMap<>::
Entity.gd::GDScript::-1::1678647319::0::1::::Entity<>Node<>:: Entity.gd::GDScript::-1::1679340919::0::1::::Entity<>Node<>::
Global.gd::GDScript::-1::1677174532::0::1::::<>Node<>:: Global.gd::GDScript::-1::1677174532::0::1::::<>Node<>::
Instance3D.gd::GDScript::-1::1677873181::0::1::::<>CharacterBody3D<>:: Instance3D.gd::GDScript::-1::1679341493::0::1::::<>CharacterBody3D<>::
Map.gd::GDScript::-1::1678219623::0::1::::<>TextureRect<>:: Map.gd::GDScript::-1::1678219623::0::1::::<>TextureRect<>::
Selection.gd::GDScript::-1::1678222510::0::1::::<>Node3D<>:: Selection.gd::GDScript::-1::1679262454::0::1::::<>Node3D<>::
World.gd::GDScript::-1::1678476426::0::1::::World<>Node<>:: World.gd::GDScript::-1::1678902652::0::1::::World<>Node<>::
WorldGeneration.gd::GDScript::-1::1678232290::0::1::::<>Control<>:: WorldGeneration.gd::GDScript::-1::1678662629::0::1::::<>Control<>::

@ -1,12 +1,8 @@
res://scenes/WorldGeneration.tscn res://scenes/HUD.tscn
res://assets/environment.tres res://assets/environment.tres
res://scripts/Instance3D.gd
res://scenes/WorldGeneration.tscn
res://scenes/3DWorld.tscn res://scenes/3DWorld.tscn
res://scenes/Instance.tscn res://scenes/Instance.tscn
res://assets/blocs/blocs.tscn res://assets/blocs/blocs.tscn
res://scenes/HUD.tscn
res://scripts/Entity.gd res://scripts/Entity.gd
res://scripts/Instance3D.gd
res://scripts/Selection.gd
res://scripts/World.gd
res://scripts/Chunks.gd
res://scripts/WorldGeneration.gd

@ -3,10 +3,10 @@
state={ state={
"bookmarks": PackedInt32Array(), "bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(), "breakpoints": PackedInt32Array(),
"column": 96, "column": 0,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 9, "row": 12,
"scroll_position": 0.0, "scroll_position": 0.0,
"selection": false, "selection": false,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
@ -20,9 +20,13 @@ state={
"column": 0, "column": 0,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 79, "row": 74,
"scroll_position": 65.0, "scroll_position": 59.0,
"selection": false, "selection": true,
"selection_from_column": 35,
"selection_from_line": 73,
"selection_to_column": 0,
"selection_to_line": 74,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
} }
@ -31,16 +35,12 @@ state={
state={ state={
"bookmarks": PackedInt32Array(), "bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(), "breakpoints": PackedInt32Array(),
"column": 0, "column": 54,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 2, "row": 74,
"scroll_position": 0.0, "scroll_position": 50.0,
"selection": true, "selection": false,
"selection_from_column": 0,
"selection_from_line": 2,
"selection_to_column": 54,
"selection_to_line": 2,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
} }
@ -52,8 +52,8 @@ state={
"column": 0, "column": 0,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 27, "row": 102,
"scroll_position": 0.0, "scroll_position": 88.0,
"selection": false, "selection": false,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
} }
@ -105,10 +105,10 @@ state={
state={ state={
"bookmarks": PackedInt32Array(), "bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(), "breakpoints": PackedInt32Array(),
"column": 57, "column": 0,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 11, "row": 14,
"scroll_position": 0.0, "scroll_position": 0.0,
"selection": false, "selection": false,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
@ -119,11 +119,11 @@ state={
state={ state={
"bookmarks": PackedInt32Array(), "bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(), "breakpoints": PackedInt32Array(),
"column": 55, "column": 5,
"folded_lines": Array[int]([]), "folded_lines": Array[int]([]),
"h_scroll_position": 0, "h_scroll_position": 0,
"row": 28, "row": 24,
"scroll_position": 12.0, "scroll_position": 0.0,
"selection": false, "selection": false,
"syntax_highlighter": "GDScript" "syntax_highlighter": "GDScript"
} }

@ -55,6 +55,7 @@ cell_octant_size = 512
cell_center_x = false cell_center_x = false
cell_center_y = false cell_center_y = false
cell_center_z = false cell_center_z = false
collision_layer = 129
data = { data = {
"cells": PackedInt32Array(1619, 64841, 0, 130877, 765, 0, 590646, 65155, 0) "cells": PackedInt32Array(1619, 64841, 0, 130877, 765, 0, 590646, 65155, 0)
} }
@ -66,6 +67,7 @@ environment = ExtResource("4_dycnn")
[node name="Ocean" type="StaticBody3D" parent="."] [node name="Ocean" type="StaticBody3D" parent="."]
transform = Transform3D(0.999999, 0, 0, 0, 1, 0, 0, 0, 1, 256, 0.5, 256) transform = Transform3D(0.999999, 0, 0, 0, 1, 0, 0, 0, 1, 256, 0.5, 256)
collision_layer = 129
[node name="Mesh" type="MeshInstance3D" parent="Ocean"] [node name="Mesh" type="MeshInstance3D" parent="Ocean"]
mesh = SubResource("PlaneMesh_7x62x") mesh = SubResource("PlaneMesh_7x62x")

@ -3,16 +3,26 @@
[ext_resource type="Script" path="res://scripts/Instance3D.gd" id="1_64ypb"] [ext_resource type="Script" path="res://scripts/Instance3D.gd" id="1_64ypb"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_qsbqh"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_qsbqh"]
radius = 0.4
height = 1.2
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ed37x"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ed37x"]
radius = 0.4
height = 1.2
[node name="Instance3D" type="CharacterBody3D"] [node name="Instance3D" type="CharacterBody3D"]
script = ExtResource("1_64ypb") script = ExtResource("1_64ypb")
[node name="Pivot" type="Node3D" parent="."] [node name="Pivot" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
[node name="MeshInstance3D" type="MeshInstance3D" parent="Pivot"] [node name="MeshInstance3D" type="MeshInstance3D" parent="Pivot"]
mesh = SubResource("CapsuleMesh_qsbqh") mesh = SubResource("CapsuleMesh_qsbqh")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
shape = SubResource("CapsuleShape3D_ed37x") shape = SubResource("CapsuleShape3D_ed37x")
[node name="RayCast3D" type="RayCast3D" parent="."]
transform = Transform3D(0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 10, 0)
collision_mask = 128

@ -2,21 +2,23 @@ extends Node
class_name Entity class_name Entity
var position: Vector3 var position: Vector2i
var position2D: Vector2i var global_speed = 10.0 # blocs per second
var speed = 3.0 # blocs per second
var id = -1 var id = -1
var moving_counter = 0 var moving_counter = 0
var path = []
var path_counter = 0
var following_path = false
signal moving signal moving
signal next_move
func _init(id: int, position: Vector2i): func _init(id: int, position: Vector2i):
self.id = id self.id = id
self.position.x = position.x self.position = position
self.position.y = Global.world.get_height(Vector2i(position.x, position.y)) next_move.connect(_path_continue)
self.position.z = position.y
position2D = position
func get_data(): func get_data():
var data = { var data = {
@ -26,42 +28,43 @@ func get_data():
return data return data
func move(new_position: Vector2i): func move(new_position: Vector2i, speed: float):
var new_position_3d = Vector3(new_position.x, Global.world.get_height(Vector2i(new_position.x, new_position.y)), new_position.y) emit_signal("moving", new_position, speed)
emit_signal("moving", new_position_3d, speed)
Global.world.blocs[position.x][position.y].entity = -1 Global.world.blocs[position.x][position.y].entity = -1
self.position = new_position_3d self.position = new_position
position2D = new_position position = new_position
Global.world.blocs[new_position.x][new_position.y].entity = id Global.world.blocs[new_position.x][new_position.y].entity = id
func follow_path(path: Array): var t = Timer.new()
moving_counter += 1 t.wait_time = 1.0 / speed
var current_moving_counter = moving_counter t.set_one_shot(true)
for next in path: t.autostart = true
Engine.get_main_loop().get_root().add_child(t)
if moving_counter != current_moving_counter: await t.timeout
return t.queue_free()
move(next) emit_signal("next_move")
var t = Timer.new()
t.wait_time = 1.0 / speed
t.set_one_shot(true)
t.autostart = true
Engine.get_main_loop().get_root().add_child(t)
await t.timeout
t.queue_free()
func heuristic(a: Vector2i, b: Vector2i) -> float: func heuristic(a: Vector2i, b: Vector2i) -> float:
return abs(a.x - b.x) + abs(a.y - b.y) return abs(a.x - b.x) + abs(a.y - b.y)
func pathfinding(goal: Vector2i): func path_create(goal: Vector2i):
if goal == position:
path = []
return
if path.size():
if path[-1] == goal:
return
var frontier = [] var frontier = []
var priorities = {} var priorities = {}
var came_from = {} var came_from = {}
var cost_so_far = {} var cost_so_far = {}
came_from[position2D] = null came_from[position] = null
cost_so_far[position2D] = 0 cost_so_far[position] = 0
frontier.append(position2D) frontier.append(position)
while frontier.size(): while frontier.size():
var current = frontier.pop_front() var current = frontier.pop_front()
@ -85,9 +88,27 @@ func pathfinding(goal: Vector2i):
) )
var current = goal var current = goal
var path = [] path = []
while current != position2D: while current != position:
path.append(current) path.append(current)
current = came_from[current] current = came_from[current]
path.reverse() path.reverse()
return path path_counter = 0
func path_go_to(index):
var next = path[index]
var distance = sqrt(pow(next.x - position.x, 2) + pow(next.y - position.y, 2))
var speed = global_speed / distance
move(next, speed)
func path_start():
if not following_path and path.size():
following_path = true
path_go_to(0)
func _path_continue():
if path_counter < path.size() - 1 and following_path:
path_counter += 1
path_go_to(path_counter)
else:
following_path = false

@ -1,13 +1,20 @@
extends CharacterBody3D extends CharacterBody3D
var id = -1 var id = -1
@onready var ray = $RayCast3D
func _process(delta):
var height = ray.get_collision_point().y
if position.y != height:
var tween = get_tree().create_tween()
tween.tween_property(self, "position:y", height, 0.1)
func connect_to_world(id): func connect_to_world(id):
var world_entity = Global.world.entities[id] var world_entity = Global.world.entities[id]
world_entity.moving.connect(_on_entity_moving) world_entity.moving.connect(_on_entity_moving)
pass
func _on_entity_moving(new_position, speed): func _on_entity_moving(new_position, speed):
var tween = get_tree().create_tween() var x_tween = get_tree().create_tween()
tween.tween_property(self, "position", new_position, 1.0/speed) var z_tween = get_tree().create_tween()
pass x_tween.tween_property(self, "position:x", new_position.x, 1.0/speed)
z_tween.tween_property(self, "position:z", new_position.y, 1.0/speed)

@ -30,8 +30,8 @@ func _process(delta):
add_child(entity_instance) add_child(entity_instance)
if Input.is_action_just_pressed("main_command"): if Input.is_action_just_pressed("main_command"):
if selection.type == 1: if selection.type == 1:
var path = Global.world.entities[selection.data.id].pathfinding(Vector2i(highlight.data.position.x, highlight.data.position.z)) var path = Global.world.entities[selection.data.id].path_create(Vector2i(highlight.data.position.x, highlight.data.position.z))
Global.world.entities[selection.data.id].follow_path(path) Global.world.entities[selection.data.id].path_start()
func _unhandled_input(event): func _unhandled_input(event):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
highlight = get_highlight() highlight = get_highlight()
@ -63,7 +63,7 @@ func get_highlight():
var position = grid.get_used_cells()[raycast_result.shape] var position = grid.get_used_cells()[raycast_result.shape]
result["type"] = 0 result["type"] = 0
result["data"] = Global.world.get_bloc(Vector2i(grid.local_to_map(raycast_result.position).x, grid.local_to_map(raycast_result.position).z)) result["data"] = Global.world.get_bloc(Vector2i(grid.local_to_map(raycast_result.position).x, grid.local_to_map(raycast_result.position).z))
elif raycast_result.collider.get("id"): elif "id" in raycast_result.collider:
result["type"] = 1 result["type"] = 1
result["data"] = Global.world.entities[raycast_result.collider.id].get_data() result["data"] = Global.world.entities[raycast_result.collider.id].get_data()
return result return result

@ -86,6 +86,6 @@ func cost(point1: Vector2i, point2: Vector2i):
(point1.x == point2.x - 1 and point1.y == point2.y + 1) or (point1.x == point2.x - 1 and point1.y == point2.y + 1) or
(point1.x == point2.x - 1 and point1.y == point2.y - 1) (point1.x == point2.x - 1 and point1.y == point2.y - 1)
): ):
cost = 2 cost = 1.1
return cost return cost

Loading…
Cancel
Save