Add NodeGroupNotifier to generalize PathNavigator
The NodeGroupNotifier notifies nodes within a specific group of the existence of a specific Node. With this new node, the Navigation does not need to be specifically assigned to the PathNavigatorForKinematicBody, making it easier to use in different scenarios.
This commit is contained in:
parent
0ee7883250
commit
c3301e15db
@ -2,21 +2,35 @@ extends Path
|
||||
|
||||
var _current_nav_path: PoolVector3Array
|
||||
|
||||
var _current_nav_index = 0
|
||||
var _current_path_index = 1
|
||||
var _current_nav_index
|
||||
var _current_path_index
|
||||
|
||||
var _arrived_distance_threshold = 0.1
|
||||
|
||||
export(float) var speed = 8
|
||||
export(NodePath) var navigation_nodepath
|
||||
export(NodePath) var body_nodepath
|
||||
|
||||
var navigation: Navigation
|
||||
var body: KinematicBody
|
||||
|
||||
|
||||
# React to the NodeGroupNotifier of the Navigation
|
||||
func set_navigator_node(navigation_node: Navigation):
|
||||
navigation = navigation_node as Navigation
|
||||
|
||||
# Our path could change significantly with the Navigation node, so restart
|
||||
_restart_navigation()
|
||||
|
||||
|
||||
func _ready():
|
||||
navigation = get_node(navigation_nodepath) as Navigation
|
||||
_restart_navigation()
|
||||
|
||||
|
||||
# Reset the body to the starting position and start the navigation freshly
|
||||
func _restart_navigation():
|
||||
_current_nav_index = 0
|
||||
_current_path_index = 1
|
||||
|
||||
body = get_node(body_nodepath) as KinematicBody
|
||||
|
||||
# Initialize the position
|
||||
@ -67,7 +81,11 @@ func _get_new_navigation():
|
||||
_current_nav_index = 0
|
||||
|
||||
var goal = curve.get_point_position(_current_path_index)
|
||||
_current_nav_path = navigation.get_simple_path(_get_body_position(), goal)
|
||||
|
||||
if navigation:
|
||||
_current_nav_path = navigation.get_simple_path(_get_body_position(), goal)
|
||||
else:
|
||||
_current_nav_path = PoolVector3Array([goal])
|
||||
|
||||
|
||||
# Return the current position of the body we're controlling
|
||||
|
@ -2,14 +2,15 @@
|
||||
|
||||
[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="Curve3D" id=4]
|
||||
[sub_resource type="Curve3D" id=1]
|
||||
_data = {
|
||||
"points": PoolVector3Array( 0, 0, 0, 0, 0, 0, -7.92509, 2.86102e-05, -6.86376, 0, 0, 0, 0, 0, 0, 0.703341, 0.398803, 1.99739, 0, 0, 0, 0, 0, 0, 9.39952, 0.263628, 7.15156, 0, 0, 0, 0, 0, 0, -4.38803, 1.73835, 6.52798 ),
|
||||
"tilts": PoolRealArray( 0, 0, 0, 0 )
|
||||
}
|
||||
|
||||
[node name="PathNavigatorForKinematicBody" type="Path"]
|
||||
curve = SubResource( 4 )
|
||||
[node name="PathNavigatorForKinematicBody" type="Path" groups=[
|
||||
"Navigator",
|
||||
]]
|
||||
curve = SubResource( 1 )
|
||||
script = ExtResource( 1 )
|
||||
navigation_nodepath = NodePath("..")
|
||||
body_nodepath = NodePath("../KinematicBody")
|
||||
|
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Characters/Meldewesen/Meldewesen.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Util/NodeGroupNotifier.tscn" type="PackedScene" id=3]
|
||||
|
||||
[sub_resource type="NavigationMesh" id=1]
|
||||
vertices = PoolVector3Array( -1.3, 0.4, -1.6, 0.200001, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -0.0999994, -1.6, 0.4, -0.0999994, -1.3, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, -1.6, 1.4, 0.4, -1.6, 1.4, 0.4, -1.6, 1.7, 0.4, -0.0999994, 9.5, 0.4, -0.0999994, 9.5, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, 9.5, 0.200001, 0.4, 8.3, -1.6, 0.4, 8, -9.4, 0.4, 9.5, -1.6, 0.4, 5, 0.200001, 0.4, 4.7, 0.200001, 0.4, 1.7, -1.6, 0.4, 1.4, -1.6, 0.4, 5, -1.6, 0.4, 1.4, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 1.4, -1.6, 0.4, -0.0999994, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 8, -1.6, 0.4, 5, 1.7, 0.4, 8, 0.200001, 0.4, 8.3, 0.200001, 0.4, 9.5, 9.5, 0.4, 9.5, 0.200001, 0.4, 1.7, 0.200001, 0.4, 4.7, 1.7, 0.4, 5, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 1.7, 0.4, 8, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, -0.0999994, 1.7, 0.4, 1.4 )
|
||||
@ -41,3 +42,7 @@ material/0 = null
|
||||
body_nodepath = NodePath("Meldewesen")
|
||||
|
||||
[node name="Meldewesen" parent="PathNavigatorForKinematicBody" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="NodeGroupNotifier" parent="." instance=ExtResource( 3 )]
|
||||
group_name = "Navigator"
|
||||
node_to_send = NodePath("..")
|
||||
|
31
Util/NodeGroupNotifier.gd
Normal file
31
Util/NodeGroupNotifier.gd
Normal file
@ -0,0 +1,31 @@
|
||||
tool
|
||||
extends Node
|
||||
|
||||
|
||||
#
|
||||
# Notifies a specific group of the existence of a node which can be assigned to this one.
|
||||
# The nodes in the group are notified via the function "set_groupname_node", e.g. "set_notifier_node",
|
||||
# which has the Node as an argument.
|
||||
#
|
||||
|
||||
|
||||
export(String) var group_name: String
|
||||
export(NodePath) var node_to_send: NodePath
|
||||
|
||||
|
||||
func _ready():
|
||||
var function_name = "set_%s_node" % [group_name.to_lower()]
|
||||
|
||||
print("Calling %s" % [function_name])
|
||||
get_tree().call_group(group_name, function_name, get_node(node_to_send))
|
||||
|
||||
|
||||
# Display a warning in the editor if the group or node is invalid
|
||||
func _get_configuration_warning():
|
||||
if !get_tree().has_group(group_name):
|
||||
return "Group does not exist!"
|
||||
|
||||
if !node_to_send:
|
||||
return "A node to send needs to be assigned!"
|
||||
|
||||
return ""
|
6
Util/NodeGroupNotifier.tscn
Normal file
6
Util/NodeGroupNotifier.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Util/NodeGroupNotifier.gd" type="Script" id=1]
|
||||
|
||||
[node name="NodeGroupNotifier" type="Node"]
|
||||
script = ExtResource( 1 )
|
@ -1,5 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user