mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Create Move
and MoveStraight
and refactor MoveTowards
This commit is contained in:
parent
fd0d973658
commit
69b08c09e7
6 changed files with 38 additions and 10 deletions
6
behaviours/move.gd
Normal file
6
behaviours/move.gd
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
@icon("res://behaviours/move.svg")
|
||||||
|
extends Node2D
|
||||||
|
class_name Move
|
||||||
|
|
||||||
|
|
||||||
|
signal move(norm: Vector2)
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -3,15 +3,15 @@
|
||||||
importer="texture"
|
importer="texture"
|
||||||
type="CompressedTexture2D"
|
type="CompressedTexture2D"
|
||||||
uid="uid://d10wobjiuh1mm"
|
uid="uid://d10wobjiuh1mm"
|
||||||
path="res://.godot/imported/move_towards.svg-f5d5c8fa66b43d0301cc029ecee0a291.ctex"
|
path="res://.godot/imported/move.svg-6291495a0c7bf9c3c43cbea535114f1a.ctex"
|
||||||
metadata={
|
metadata={
|
||||||
"vram_texture": false
|
"vram_texture": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://behaviours/move_towards.svg"
|
source_file="res://behaviours/move.svg"
|
||||||
dest_files=["res://.godot/imported/move_towards.svg-f5d5c8fa66b43d0301cc029ecee0a291.ctex"]
|
dest_files=["res://.godot/imported/move.svg-6291495a0c7bf9c3c43cbea535114f1a.ctex"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
17
behaviours/move_straight.gd
Normal file
17
behaviours/move_straight.gd
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
@icon("res://behaviours/move.svg")
|
||||||
|
extends Move
|
||||||
|
class_name MoveStraight
|
||||||
|
|
||||||
|
|
||||||
|
## A [Move] that moves in a fixed direction.
|
||||||
|
|
||||||
|
|
||||||
|
@export var direction: Vector2
|
||||||
|
|
||||||
|
|
||||||
|
func randomize_direction() -> void:
|
||||||
|
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(_delta: float) -> void:
|
||||||
|
move.emit(direction)
|
6
behaviours/move_straight.tscn
Normal file
6
behaviours/move_straight.tscn
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dk1ipq7dhkhf3"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://behaviours/move_straight.gd" id="1_8yf73"]
|
||||||
|
|
||||||
|
[node name="MoveStraight" type="Node2D"]
|
||||||
|
script = ExtResource("1_8yf73")
|
|
@ -1,12 +1,9 @@
|
||||||
@icon("res://behaviours/move_towards.svg")
|
@icon("res://behaviours/move.svg")
|
||||||
extends Node2D
|
extends Move
|
||||||
class_name MoveTowards
|
class_name MoveTowards
|
||||||
|
|
||||||
|
|
||||||
## A node emitting the [signal move] signal each physics timestep to move towards the position of [field target].
|
## A [Move] that moves towards the [field position] of a [field target].
|
||||||
|
|
||||||
|
|
||||||
signal move(norm: Vector2)
|
|
||||||
|
|
||||||
|
|
||||||
@export var target: Node2D = null
|
@export var target: Node2D = null
|
||||||
|
@ -28,3 +25,5 @@ func _physics_process(_delta: float) -> void:
|
||||||
var gap = target.global_position - global_position
|
var gap = target.global_position - global_position
|
||||||
var norm = gap.normalized()
|
var norm = gap.normalized()
|
||||||
move.emit(norm)
|
move.emit(norm)
|
||||||
|
else:
|
||||||
|
move.emit(Vector2.ZERO)
|
||||||
|
|
Loading…
Reference in a new issue