Add static movement behavior option

This commit is contained in:
antimundo 2025-04-26 20:48:11 +02:00
parent a235066cd9
commit cdda8100a9
6 changed files with 27 additions and 18 deletions

View file

@ -3,12 +3,11 @@
[ext_resource type="Script" uid="uid://eap3623705g4" path="res://scenes/game_world/scenario/scenario.gd" id="1_xogef"]
[ext_resource type="PackedScene" uid="uid://dagqtbldaccgh" path="res://scenes/game_world/scenario/sample_world_geometry.tscn" id="2_xogef"]
[ext_resource type="Script" uid="uid://7eouyjvbgjo0" path="res://scenes/game_world/target_spawner.gd" id="3_tfn8e"]
[ext_resource type="Script" uid="uid://bxhkdvu8k5owt" path="res://scenes/target/behavior/behavior_linearmovement.gd" id="4_aotl8"]
[ext_resource type="Script" uid="uid://bw3onig2m2r3s" path="res://scenes/target/behavior/behavior_static.gd" id="4_8xptx"]
[sub_resource type="Resource" id="Resource_ncddh"]
script = ExtResource("4_aotl8")
max_velocity = Vector3(0, 0, 0)
metadata/_custom_type_script = "uid://bxhkdvu8k5owt"
[sub_resource type="Resource" id="Resource_u06mb"]
script = ExtResource("4_8xptx")
metadata/_custom_type_script = "uid://bw3onig2m2r3s"
[node name="Scenario" type="Node3D" node_paths=PackedStringArray("_light")]
script = ExtResource("1_xogef")
@ -27,4 +26,4 @@ script = ExtResource("3_tfn8e")
size = Vector2(1, 0.5)
min_position = Vector3(-15, 0, 0)
max_position = Vector3(15, 0, 0)
behavior = SubResource("Resource_ncddh")
behavior = SubResource("Resource_u06mb")

View file

@ -3,12 +3,11 @@
[ext_resource type="Script" uid="uid://eap3623705g4" path="res://scenes/game_world/scenario/scenario.gd" id="1_xogef"]
[ext_resource type="PackedScene" uid="uid://dagqtbldaccgh" path="res://scenes/game_world/scenario/sample_world_geometry.tscn" id="2_xogef"]
[ext_resource type="Script" uid="uid://7eouyjvbgjo0" path="res://scenes/game_world/target_spawner.gd" id="3_tfn8e"]
[ext_resource type="Script" uid="uid://bxhkdvu8k5owt" path="res://scenes/target/behavior/behavior_linearmovement.gd" id="4_aotl8"]
[ext_resource type="Script" uid="uid://bw3onig2m2r3s" path="res://scenes/target/behavior/behavior_static.gd" id="4_xogef"]
[sub_resource type="Resource" id="Resource_ncddh"]
script = ExtResource("4_aotl8")
max_velocity = Vector3(0, 0, 0)
metadata/_custom_type_script = "uid://bxhkdvu8k5owt"
[sub_resource type="Resource" id="Resource_wx1lo"]
script = ExtResource("4_xogef")
metadata/_custom_type_script = "uid://bw3onig2m2r3s"
[node name="Scenario" type="Node3D" node_paths=PackedStringArray("_light")]
script = ExtResource("1_xogef")
@ -27,4 +26,4 @@ script = ExtResource("3_tfn8e")
initial_targets = 3
min_position = Vector3(-5, -2, 0)
max_position = Vector3(5, 2, 0)
behavior = SubResource("Resource_ncddh")
behavior = SubResource("Resource_wx1lo")

View file

@ -1,5 +1,6 @@
extends TargetMovementBehavior
class_name TargetMovementBehaviorLinearmovement
extends TargetMovementBehavior
## A target movement behavior that moves linearly in a straight line
## Max velocity of the target
@export var max_velocity: Vector3 = Vector3.ZERO
@ -7,9 +8,9 @@ class_name TargetMovementBehaviorLinearmovement
var min_position: Vector3
var max_position: Vector3
func init(new_min_position: Vector3, new_max_position, movement = {"x": 0, "y": 0}) -> void:
_current_velocity = Vector3(randf_range(-movement.x, movement.x),\
randf_range(-movement.y, movement.y), 0)
func init(new_min_position: Vector3, new_max_position: Vector3) -> void:
_current_velocity = Vector3(randf_range(-max_velocity.x, max_velocity.x),\
randf_range(-max_velocity.y, max_velocity.y), 0)
min_position = new_min_position
max_position = new_max_position

View file

@ -0,0 +1,9 @@
extends TargetMovementBehavior
class_name TargetMovementBehaviorStatic
## A target movement behavior that doesn't move
func init(_new_min_position: Vector3, _new_max_position: Vector3) -> void:
pass
func move_process(_delta: float, _position: Vector3) -> Vector3:
return Vector3.ZERO

View file

@ -0,0 +1 @@
uid://bw3onig2m2r3s

View file

@ -1,5 +1,5 @@
extends CharacterBody3D
class_name Target
extends CharacterBody3D
## A target for the player to shoot at
signal destroyed ## When player destroys the target
@ -27,7 +27,7 @@ func init(size = Vector2(1.0, 2.0), behavior: TargetMovementBehavior = TargetMov
collision_shape.shape.height = size.y
_mesh_instance.mesh.radius = size.x
_mesh_instance.mesh.height = size.y
behavior.init(min_position, max_position, behavior.max_velocity)
behavior.init(min_position, max_position)
movement_behavior = behavior
_set_health(new_health)