1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Make Sheep throwable!

This commit is contained in:
Steffo 2024-04-20 04:54:33 +02:00
parent f9f52c4f4a
commit 6e14678239
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 54 additions and 23 deletions

View file

@ -0,0 +1,39 @@
extends Move
class_name MoveTowardsGravity
signal dragged(cursor: Cursor)
signal dropped
signal fallen
@export var acceleration = 2500.0
@export var linear_damp = 50.0
var cursor: Cursor = null
var velocity := Vector2.ZERO
@onready var ticks_per_second = ProjectSettings.get_setting("physics/common/physics_ticks_per_second")
func drag(value: Cursor) -> void:
cursor = value
dragged.emit(value)
func drop() -> void:
cursor = null
dropped.emit()
func fall() -> void:
velocity = Vector2.ZERO
fallen.emit()
func _physics_process(delta: float) -> void:
if enabled:
if cursor:
var gap = cursor.global_position - global_position
velocity += gap * delta * acceleration
velocity *= 1.0 - linear_damp / ticks_per_second
move.emit(velocity * delta)

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://rx24bppccih7"]
[ext_resource type="Script" path="res://behaviours/move_towards_physics.gd" id="1_u02i3"]
[ext_resource type="Script" path="res://behaviours/move_physics.gd" id="1_u02i3"]
[node name="MoveTowardsPhysics" type="Node2D"]
script = ExtResource("1_u02i3")

View file

@ -1,17 +0,0 @@
extends MoveTowards
class_name MoveTowardsGravity
# [field speed] is actually used as acceleration. Oh well.
var velocity := Vector2.ZERO
func _physics_process(delta: float) -> void:
if enabled:
if target:
var gap = target.global_position - global_position
var norm = gap.normalized()
velocity += norm * delta * speed
Log.p(self, "Velocity: %s" % velocity)
move.emit(velocity * delta)

View file

@ -13,7 +13,7 @@
[ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/cursor_detector.tscn" id="13_5fkdr"]
[ext_resource type="PackedScene" uid="uid://dti7l0d40hhgt" path="res://behaviours/target_picker.tscn" id="13_jf6em"]
[ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="14_0b1hs"]
[ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_towards_physics.tscn" id="14_3wojv"]
[ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_physics.tscn" id="14_3wojv"]
[ext_resource type="PackedScene" uid="uid://c5pyp5hvthdof" path="res://behaviours/tracker_tracker.tscn" id="14_eqowb"]
[sub_resource type="CircleShape2D" id="CircleShape2D_c5tcn"]
@ -164,7 +164,9 @@ debug_color = Color(1, 1, 0, 0)
tracker = NodePath("..")
[node name="MovementDrag" parent="." instance=ExtResource("14_3wojv")]
speed = 1200.0
acceleration = 650.0
linear_damp = 18.0
enabled = false
[node name="DragPriority" parent="MovementDrag" instance=ExtResource("11_0jlmk")]
alternative_priority = 50
@ -176,6 +178,10 @@ scale = Vector2(3, 3)
shape = SubResource("CircleShape2D_c5tcn")
debug_color = Color(1, 1, 1, 0)
[node name="FallTimer" type="Timer" parent="MovementDrag"]
wait_time = 0.5
one_shot = true
[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"]
[connection signal="move" from="MovementIdle" to="." method="_on_move"]
[connection signal="move_disabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="stop"]
@ -201,11 +207,14 @@ debug_color = Color(1, 1, 1, 0)
[connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="set_target_if_null"]
[connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="clear_if_target"]
[connection signal="target_changed" from="MovementRunFromHunter/HunterSense/TargetPicker" to="MovementRunFromHunter" method="set_target" unbinds=1]
[connection signal="changed_target" from="MovementDrag" to="MovementDrag/DragPriority" method="priority_conditional"]
[connection signal="dragged" from="MovementDrag" to="MovementDrag/DragPriority" method="priority_alternative" unbinds=1]
[connection signal="dropped" from="MovementDrag" to="MovementDrag/FallTimer" method="start"]
[connection signal="fallen" from="MovementDrag" to="MovementDrag/DragPriority" method="priority_default"]
[connection signal="move" from="MovementDrag" to="." method="_on_move"]
[connection signal="move_enabled" from="MovementDrag" to="MovementWander" method="clear_direction"]
[connection signal="priority_changed_no_args" from="MovementDrag/DragPriority" to="MovementSampler" method="enable"]
[connection signal="dragged" from="MovementDrag/Draggable" to="." method="_on_draggable_dragged"]
[connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="set_target"]
[connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"]
[connection signal="dropped" from="MovementDrag/Draggable" to="." method="_on_draggable_dropped"]
[connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="clear_target"]
[connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"]
[connection signal="timeout" from="MovementDrag/FallTimer" to="MovementDrag" method="fall"]