more random movement toward target
This commit is contained in:
parent
d4ffe758ea
commit
9e2a513692
13
core/battlefield.gd
Normal file
13
core/battlefield.gd
Normal file
|
@ -0,0 +1,13 @@
|
|||
extends Node2D
|
||||
|
||||
var _ticker1 := 0.0
|
||||
|
||||
func _physics_process(delta):
|
||||
_ticker1 += delta
|
||||
if _ticker1 > 1.0:
|
||||
_ticker1 -= 1.0
|
||||
ticker("ticker1")
|
||||
|
||||
func ticker(group_name: String):
|
||||
for node in get_tree().get_nodes_in_group(group_name):
|
||||
node.tick()
|
|
@ -1,3 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://brbtq46uk18gg"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://brbtq46uk18gg"]
|
||||
|
||||
[ext_resource type="Script" path="res://core/battlefield.gd" id="1_u7icn"]
|
||||
|
||||
[node name="battlefield" type="Node2D"]
|
||||
script = ExtResource("1_u7icn")
|
||||
|
|
|
@ -29,12 +29,10 @@ func _compose():
|
|||
|
||||
func _physics_process(delta):
|
||||
if not target_reached:
|
||||
# TODO use position instead of position, once parented to battlefield
|
||||
# TODO use position instead of global_position, once parented to battlefield
|
||||
global_position += (target_position - global_position).normalized() * 100.0 * delta
|
||||
if global_position == target_position:
|
||||
target_reached = true
|
||||
|
||||
make_decision() # TODO not every tick
|
||||
|
||||
func move_to(pos: Vector2):
|
||||
if pos != target_position:
|
||||
|
@ -48,6 +46,3 @@ func damage(lost_hitpoints: float):
|
|||
|
||||
func die():
|
||||
queue_free()
|
||||
|
||||
func make_decision():
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends Unit
|
||||
|
||||
func make_decision():
|
||||
func tick():
|
||||
# go to nearest enemy
|
||||
var enemy: Unit = null
|
||||
var closest := INF
|
||||
|
@ -11,5 +11,5 @@ func make_decision():
|
|||
closest = distance
|
||||
enemy = unit
|
||||
if enemy:
|
||||
move_to(enemy.global_position)
|
||||
move_to(enemy.global_position + Vector2.from_angle(randf_range(0.0, PI * 2.0)) * randf_range(100.0, 300.0))
|
||||
$turret.set_target(enemy)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[ext_resource type="Texture2D" uid="uid://2nhprnyswhyh" path="res://tac/assets/ship_small_1.png" id="2_oablw"]
|
||||
[ext_resource type="PackedScene" uid="uid://byg2bmiy2gia0" path="res://tac/weapons/turret.tscn" id="3_rt3r8"]
|
||||
|
||||
[node name="fighter" instance=ExtResource("1_2ka4q")]
|
||||
[node name="fighter" groups=["ticker1"] instance=ExtResource("1_2ka4q")]
|
||||
script = ExtResource("2_evq3k")
|
||||
hitpoints = 20
|
||||
|
||||
|
|
Loading…
Reference in a new issue