diff --git a/godot/Demos/GroupBehaviors/GroupBehaviorsDemo.tscn b/godot/Demos/GroupBehaviors/GroupBehaviorsDemo.tscn index 2f27d9a..2fb5437 100644 --- a/godot/Demos/GroupBehaviors/GroupBehaviorsDemo.tscn +++ b/godot/Demos/GroupBehaviors/GroupBehaviorsDemo.tscn @@ -6,6 +6,7 @@ [ext_resource path="res://Demos/Utils/DemoInterface.tscn" type="PackedScene" id=4] [ext_resource path="res://Demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=5] + [node name="GroupBehaviorsDemo" type="Node"] script = ExtResource( 3 ) linear_accel_max = 4234.0 @@ -17,10 +18,12 @@ separation_strength = 8.8 [node name="BackgroudLayer" parent="." instance=ExtResource( 5 )] [node name="Spawner" type="Node2D" parent="."] -position = Vector2( 512, 300 ) +position = Vector2( 973.261, 528.829 ) script = ExtResource( 2 ) member = ExtResource( 1 ) [node name="DemoInterface" parent="." instance=ExtResource( 4 )] +mouse_filter = 2 text_bbcode = "Group Behavior Demo -Each of the \"Agents\" are both attempting to stay separated from each other but within reach of their nearest group's center of mass." +Each of the \"Agents\" are both attempting to stay separated from each other but within reach of their nearest group's center of mass. +Click on agent to see it's proximity." diff --git a/godot/Demos/GroupBehaviors/Member.tscn b/godot/Demos/GroupBehaviors/Member.tscn index 63207e1..7dd9ab8 100644 --- a/godot/Demos/GroupBehaviors/Member.tscn +++ b/godot/Demos/GroupBehaviors/Member.tscn @@ -3,10 +3,12 @@ [ext_resource path="res://Demos/GroupBehaviors/Member.gd" type="Script" id=1] [ext_resource path="res://Demos/Utils/CircleDraw.gd" type="Script" id=3] + [sub_resource type="CircleShape2D" id=1] radius = 16.0 [node name="Member" type="KinematicBody2D"] +input_pickable = true script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/godot/Demos/GroupBehaviors/Spawner.gd b/godot/Demos/GroupBehaviors/Spawner.gd index d4b7193..75bd1ae 100644 --- a/godot/Demos/GroupBehaviors/Spawner.gd +++ b/godot/Demos/GroupBehaviors/Spawner.gd @@ -2,7 +2,16 @@ extends Node2D export var member: PackedScene - +func follower_input_event(viewport: Node, event: InputEvent, shape_idx: int, follower:KinematicBody2D): + if event is InputEventMouseButton: + if event.button_index == BUTTON_LEFT and event.pressed: + for other in get_children(): + if other.draw_proximity: + other.draw_proximity = false + other.update() + follower.draw_proximity = true + follower.update() + move_child(follower,get_children().size()) func setup( linear_speed_max: float, linear_accel_max: float, @@ -14,7 +23,7 @@ func setup( ) -> void: var followers := [] for i in range(19): - var follower := member.instance() + var follower : KinematicBody2D = member.instance() add_child(follower) follower.position += Vector2(rand_range(-60, 60), rand_range(-60, 60)) followers.append(follower) @@ -29,6 +38,7 @@ func setup( if i == 0 and show_proximity_radius: follower.draw_proximity = true follower.update() + follower.connect("input_event",self,"follower_input_event",[follower]) var agents := [] for i in followers: agents.append(i.agent) diff --git a/godot/project.godot b/godot/project.godot index 2de5182..b33b93c 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "Reference", +"base": "Control", "class": "DemoPickerUI", "language": "GDScript", "path": "res://Demos/DemoPickerUI.gd"