From a04ff9bd2f62a40e936573b83f9dbe1c05598043 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Wed, 31 Aug 2022 16:43:15 +0200 Subject: [PATCH] Tweaked terrain hex mesh --- .gitignore | 2 ++ project.godot | 8 ++++---- scenes/HexGrid3DTest.gd | 6 +++--- scenes/HexGrid3DTest.tscn | 15 +++++++++++++-- scenes/HexTile3D.gd | 11 ++++++----- scenes/HexTile3D.tscn | 26 ++++++++++++++------------ 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 00de078..b6d8c97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .import/* .mono/* *.swp +*.apk +*.idsig diff --git a/project.godot b/project.godot index d220993..aef90b4 100644 --- a/project.godot +++ b/project.godot @@ -9,17 +9,17 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "Reference", "class": "ClickableComponent", "language": "GDScript", "path": "res://components/ClickableComponent.gd" }, { -"base": "KinematicBody2D", +"base": "Reference", "class": "CollisionLine", "language": "GDScript", "path": "res://utils/CollisionLine.gd" }, { -"base": "Node", +"base": "Reference", "class": "ColorComponent", "language": "GDScript", "path": "res://components/ColorComponent.gd" @@ -29,7 +29,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://utils/SpringDamper.gd" }, { -"base": "Sprite", +"base": "Reference", "class": "TintedSpriteComponent", "language": "GDScript", "path": "res://components/TintedSpriteComponent.gd" diff --git a/scenes/HexGrid3DTest.gd b/scenes/HexGrid3DTest.gd index b2913eb..6fcfec9 100644 --- a/scenes/HexGrid3DTest.gd +++ b/scenes/HexGrid3DTest.gd @@ -9,7 +9,7 @@ onready var tile_pos_label = $CanvasLayer/HBoxContainer/TilePos onready var player = $Player var player_velocity = Vector3.ZERO -var player_speed = 10 +var player_speed = 5 var target_coordinate = Vector3.ZERO var target_tile = null var current_tile = null @@ -24,7 +24,7 @@ func _ready(): for j in range (-num_tiles_z / 2, num_tiles_z / 2): var pos = hexgrid.get_hex_center_from_offset(Vector2(i, j)) var tile = HexTile3D.instance() - var height = (sin(pos.y * 0.3) * sin(pos.y * 0.8) * 0.8 + cos ((pos.x) * 0.9) * 1.24) * 0.5 - 0.5 + var height = (sin(pos.y * 0.3) * sin(pos.y * 0.8) * 0.8 + cos ((pos.x) * 0.9) * 1.24) * 0.5 + 0.4 + rand_range(-0.3, 0.3) tile.transform.origin = Vector3(pos.x, height, pos.y) tile.connect("tile_selected", self, "on_tile_selected") tile.connect("tile_mouse_entered", self, "on_tile_hover") @@ -58,7 +58,7 @@ func _physics_process(delta): func on_tile_selected(tile): target_tile = tile - target_coordinate = Vector3(tile.transform.origin.x, tile.transform.origin.z, tile.transform.origin.z) + target_coordinate = Vector3(tile.transform.origin.x, tile.transform.origin.y, tile.transform.origin.z) var position_error = target_coordinate - player.transform.origin print ("clicked on tile " + str(tile.transform.origin) + " error: " + str(position_error)) diff --git a/scenes/HexGrid3DTest.tscn b/scenes/HexGrid3DTest.tscn index 1d9dfb9..27fdfc8 100644 --- a/scenes/HexGrid3DTest.tscn +++ b/scenes/HexGrid3DTest.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://scenes/HexTile3D.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/HexGrid3DTest.gd" type="Script" id=2] @@ -72,6 +72,8 @@ radius = 0.2 mid_height = 0.5 radial_segments = 16 +[sub_resource type="NoiseTexture" id=5] + [node name="HexGrid3DTest" type="Spatial"] script = ExtResource( 2 ) @@ -133,7 +135,7 @@ __meta__ = { [node name="Player" type="Spatial" parent="."] [node name="Camera" type="Camera" parent="Player"] -transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, 0, 2.72642, 1.60656 ) +transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 6.70866, 3.34822 ) current = true fov = 60.0 script = ExtResource( 3 ) @@ -142,3 +144,12 @@ script = ExtResource( 3 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) mesh = SubResource( 4 ) material/0 = null + +[node name="TextureRect" type="TextureRect" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 +texture = SubResource( 5 ) +expand = true +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/scenes/HexTile3D.gd b/scenes/HexTile3D.gd index 362248e..7737f65 100644 --- a/scenes/HexTile3D.gd +++ b/scenes/HexTile3D.gd @@ -1,6 +1,7 @@ -extends MeshInstance +extends Spatial onready var is_mouse_over = false +onready var mesh = $Mesh var old_material_override = Material.new() signal tile_selected @@ -9,18 +10,18 @@ signal tile_mouse_entered func _on_Area_mouse_entered(): is_mouse_over = true - old_material_override = material_override + old_material_override = mesh.material_override - var material = self.get_surface_material(0) + var material = mesh.get_surface_material(0) var cloned_material = material.duplicate() cloned_material.albedo_color = Color (1, 0, 0) - self.material_override = cloned_material + mesh.material_override = cloned_material emit_signal("tile_mouse_entered", self) func _on_Area_mouse_exited(): is_mouse_over = false - self.material_override = old_material_override + mesh.material_override = old_material_override func _on_Area_input_event(camera, event, position, normal, shape_idx): diff --git a/scenes/HexTile3D.tscn b/scenes/HexTile3D.tscn index 1b8d64d..d740a68 100644 --- a/scenes/HexTile3D.tscn +++ b/scenes/HexTile3D.tscn @@ -9,25 +9,27 @@ height = 1.0 radial_segments = 6 rings = 1 -[sub_resource type="SpatialMaterial" id=4] -albedo_color = Color( 0.211765, 0.568627, 0.0666667, 1 ) -roughness = 0.0 +[sub_resource type="SpatialMaterial" id=7] +albedo_color = Color( 0.160784, 0.384314, 0.0901961, 1 ) [sub_resource type="CylinderShape" id=5] radius = 0.5 height = 1.0 -[node name="HexTile3D" type="MeshInstance"] -transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, -0.5, 0 ) -mesh = SubResource( 6 ) -material/0 = SubResource( 4 ) +[node name="HexTile3D" type="Spatial"] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 0 ) script = ExtResource( 1 ) -[node name="Area" type="Area" parent="."] +[node name="Mesh" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0 ) +mesh = SubResource( 6 ) +material/0 = SubResource( 7 ) -[node name="CollisionShape" type="CollisionShape" parent="Area"] +[node name="Area" type="Area" parent="Mesh"] + +[node name="CollisionShape" type="CollisionShape" parent="Mesh/Area"] shape = SubResource( 5 ) -[connection signal="input_event" from="Area" to="." method="_on_Area_input_event"] -[connection signal="mouse_entered" from="Area" to="." method="_on_Area_mouse_entered"] -[connection signal="mouse_exited" from="Area" to="." method="_on_Area_mouse_exited"] +[connection signal="input_event" from="Mesh/Area" to="." method="_on_Area_input_event"] +[connection signal="mouse_entered" from="Mesh/Area" to="." method="_on_Area_mouse_entered"] +[connection signal="mouse_exited" from="Mesh/Area" to="." method="_on_Area_mouse_exited"]