mirror of
https://github.com/RYGhub/the-cold-night.git
synced 2024-11-22 04:34:19 +00:00
✨ Add an erratic movement behaviour
This commit is contained in:
parent
19f0f88807
commit
0c7d39a815
3 changed files with 22 additions and 3 deletions
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/mechanics/Black.png" type="Texture" id=1]
|
[ext_resource path="res://src/mechanics/Black.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://src/entities/behaviours/AttractedTo.gd" type="Script" id=2]
|
[ext_resource path="res://src/entities/behaviours/AttractedTo.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://src/entities/behaviours/ErraticMovement.gd" type="Script" id=3]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
extents = Vector2( 16, 16 )
|
extents = Vector2( 16, 16 )
|
||||||
|
@ -11,6 +12,9 @@ extents = Vector2( 16, 16 )
|
||||||
[node name="AttractedTo" type="Node" parent="."]
|
[node name="AttractedTo" type="Node" parent="."]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="ErraticMovement" type="Node" parent="."]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite" parent="."]
|
[node name="Sprite" type="Sprite" parent="."]
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@ extends Node
|
||||||
|
|
||||||
|
|
||||||
export var movement_per_second: float = 32.0
|
export var movement_per_second: float = 32.0
|
||||||
|
export var goal_absolute_path: String = "Game/Fire"
|
||||||
|
|
||||||
|
|
||||||
onready var target: KinematicBody2D = get_parent()
|
onready var target: KinematicBody2D = get_parent()
|
||||||
# TODO: Use a better algorithm
|
# TODO: Use a better algorithm
|
||||||
onready var goal: StaticBody2D = get_parent().get_parent().get_node("Fire")
|
onready var goal: StaticBody2D = get_tree().root.get_node(goal_absolute_path)
|
||||||
|
|
||||||
|
|
||||||
signal touching_goal
|
signal touching_goal
|
||||||
|
@ -23,4 +24,4 @@ func _physics_process(_delta):
|
||||||
emit_signal("touching_goal")
|
emit_signal("touching_goal")
|
||||||
if not goal_reached_triggered:
|
if not goal_reached_triggered:
|
||||||
emit_signal("goal_reached")
|
emit_signal("goal_reached")
|
||||||
goal_reached_triggered = true
|
goal_reached_triggered = true
|
||||||
|
|
14
src/entities/behaviours/ErraticMovement.gd
Normal file
14
src/entities/behaviours/ErraticMovement.gd
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
export var movement_per_second: float = 16.0
|
||||||
|
|
||||||
|
|
||||||
|
onready var target: KinematicBody2D = get_parent()
|
||||||
|
onready var rng = RandomNumberGenerator.new()
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(_delta):
|
||||||
|
var direction: Vector2 = Vector2(rng.randf_range(-1, 1), rng.randf_range(-1, 1)).normalized()
|
||||||
|
var _motion: Vector2 = target.move_and_slide(direction * movement_per_second, Vector2.ZERO)
|
||||||
|
|
Loading…
Reference in a new issue