mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2025-01-09 22:09:37 +01:00
Make group members show their radius on click
* GroupBehaviours Demo: Click on member to see radius * fixed groupbehaviour demo
This commit is contained in:
parent
84e52bfd79
commit
d1c87d96b3
@ -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."
|
||||
|
@ -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="."]
|
||||
|
@ -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)
|
||||
|
@ -9,7 +9,7 @@
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Reference",
|
||||
"base": "Control",
|
||||
"class": "DemoPickerUI",
|
||||
"language": "GDScript",
|
||||
"path": "res://Demos/DemoPickerUI.gd"
|
||||
|
Loading…
Reference in New Issue
Block a user