add controlled unit move target indicator

This commit is contained in:
Teatov 2024-10-21 19:33:28 +10:00
parent ab2ff86c8a
commit e999c0002d
5 changed files with 66 additions and 1 deletions

BIN
assets/textures/move_target.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dusadvumlagrq"
path.s3tc="res://.godot/imported/move_target.png-9737dedba86278778bc0199cdb663eb6.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://assets/textures/move_target.png"
dest_files=["res://.godot/imported/move_target.png-9737dedba86278778bc0199cdb663eb6.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View File

@ -0,0 +1,12 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://dgsd4m4dnqddv"]
[ext_resource type="Texture2D" uid="uid://dusadvumlagrq" path="res://assets/textures/move_target.png" id="1_a26g5"]
[resource]
transparency = 2
alpha_scissor_threshold = 0.5
alpha_antialiasing_mode = 0
shading_mode = 0
albedo_texture = ExtResource("1_a26g5")
disable_receive_shadows = true
billboard_keep_scale = true

View File

@ -1,17 +1,28 @@
[gd_scene load_steps=5 format=3 uid="uid://cidd3q2tet7ku"]
[gd_scene load_steps=7 format=3 uid="uid://cidd3q2tet7ku"]
[ext_resource type="PackedScene" uid="uid://c70vx0utm5knp" path="res://scenes/units/abstract/unit.tscn" id="1_iivmb"]
[ext_resource type="Script" path="res://scripts/units/abstract/controlled_unit.gd" id="2_ruawn"]
[ext_resource type="Material" uid="uid://bghl8uypb17xy" path="res://resources/materials/indicators/select_indicator_mat.tres" id="3_3totu"]
[ext_resource type="Material" uid="uid://dgsd4m4dnqddv" path="res://resources/materials/indicators/move_target_mat.tres" id="3_7b21u"]
[sub_resource type="QuadMesh" id="QuadMesh_4fevy"]
material = ExtResource("3_3totu")
center_offset = Vector3(0, 0.001, 0)
orientation = 1
[sub_resource type="QuadMesh" id="QuadMesh_ewb03"]
material = ExtResource("3_7b21u")
center_offset = Vector3(0, 0.001, 0)
orientation = 1
[node name="ControlledUnit" instance=ExtResource("1_iivmb")]
script = ExtResource("2_ruawn")
[node name="SelectionIndicator" type="MeshInstance3D" parent="." index="6"]
cast_shadow = 0
mesh = SubResource("QuadMesh_4fevy")
[node name="MoveTarget" type="MeshInstance3D" parent="." index="7"]
top_level = true
cast_shadow = 0
mesh = SubResource("QuadMesh_ewb03")

View File

@ -12,6 +12,7 @@ var _is_moving: bool = false
var _ground_plane: Plane = Plane(Vector3.UP, 0)
@onready var selection_indicator: VisualInstance3D = $SelectionIndicator
@onready var move_target_indicator: VisualInstance3D = $MoveTarget
static func get_cost() -> int:
@ -34,6 +35,7 @@ func _process(delta: float) -> void:
super._process(delta)
selection_indicator.visible = _selected
hover_indicator.visible = _hovered or _hovered_rect
move_target_indicator.visible = _is_moving and (_selected or showing_info)
func _physics_process(delta: float) -> void:
@ -80,6 +82,8 @@ func set_selected(on: bool) -> void:
func navigate(to: Vector3, moving: bool = false) -> void:
_is_moving = moving
nav_agent.set_target_position(to)
if _is_moving:
move_target_indicator.global_position = nav_agent.target_position
func _interact(with: Interactable) -> void: