proto3 initial commit

This commit is contained in:
Segey Lapin
2020-04-13 12:45:25 +03:00
parent 69410badf6
commit 1084b6d5c3
1588 changed files with 368852 additions and 23 deletions

View File

@@ -0,0 +1,36 @@
extends KinematicBody
var orientation = Transform()
var velocity = Vector3()
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var front_result = {}
var front_left_result = {}
var front_right_result = {}
var low_obstacle_result = {}
var unp_fixup_angle = 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
add_to_group("agent")
unp_fixup_angle = (PI / 2.0 + PI / 2.0 * randf()) * sign(0.5 - randf())
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _physics_process(delta):
orientation *= Transform().translated(Vector3(0, 0, -1) * 0.1)
var h_velocity = orientation.origin / delta
velocity.x = h_velocity.x
velocity.z = h_velocity.z
velocity.y = h_velocity.y
# if !get_meta("grabbed") && !in_smart_obj && !disable_gravity:
velocity.y += -9.8
velocity = move_and_slide(velocity,Vector3(0,1,0))
orientation.origin = Vector3()
orientation = orientation.orthonormalized()
global_transform.basis = orientation.basis

View File

@@ -0,0 +1,60 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
for k in $VBoxContainer/list.get_children():
k.queue_free()
var dst = INF
var player_pos = global.player.global_transform.origin
for k in get_tree().get_nodes_in_group("npc"):
var hb = HBoxContainer.new()
var label1 = Label.new()
label1.text = k.name
var label2 = Label.new()
if k.has_meta("action"):
label2.text = k.get_meta("action")
else:
label2.text = "unknown action"
hb.add_child(label1)
hb.add_child(label2)
$VBoxContainer/list.add_child(hb)
var npc_pos = k.global_transform.origin
var ndst = player_pos.distance_squared_to(npc_pos)
if ndst < dst:
var bb = k.get_node("blackboard")
$VBoxContainer/closest/name.text = k.name
dst = ndst
if k.has_meta("action"):
$VBoxContainer/closest/action.text = "action: " + k.get_meta("action")
var enemy = bb.get("closest_enemy")
if enemy:
$VBoxContainer/closest/closest_enemy.text = "enemy: " + enemy.name
else:
$VBoxContainer/closest/closest_enemy.text = "no enemy"
if k.has_meta("target_group"):
$VBoxContainer/closest/target_group.text = "target: " + k.get_meta("target_group")
else:
$VBoxContainer/closest/target_group.text = ""
if k.has_meta("target_loc"):
$VBoxContainer/closest/target_loc.text = "target loc: " + str(k.get_meta("target_loc"))
else:
$VBoxContainer/closest/target_loc.text = ""
if k.has_meta("path"):
$VBoxContainer/closest/path.text = "path: " + str(k.get_meta("path"))
else:
$VBoxContainer/closest/path.text = ""
if k.has_meta("path_point"):
$VBoxContainer/closest/path_point.text = "path point: " + str(k.get_meta("path_point"))
else:
$VBoxContainer/closest/path_point.text = ""

View File

@@ -0,0 +1,74 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scenes/debug/ai_debug.gd" type="Script" id=1]
[node name="ai_debug" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="list" type="VBoxContainer" parent="VBoxContainer"]
margin_right = 1024.0
margin_bottom = 298.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="closest" type="VBoxContainer" parent="VBoxContainer"]
margin_top = 302.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="name" type="Label" parent="VBoxContainer/closest"]
margin_right = 1024.0
margin_bottom = 14.0
text = "name"
[node name="action" type="Label" parent="VBoxContainer/closest"]
margin_top = 18.0
margin_right = 1024.0
margin_bottom = 32.0
text = "action"
[node name="closest_enemy" type="Label" parent="VBoxContainer/closest"]
margin_top = 36.0
margin_right = 1024.0
margin_bottom = 50.0
text = "action"
[node name="target_group" type="Label" parent="VBoxContainer/closest"]
margin_top = 54.0
margin_right = 1024.0
margin_bottom = 68.0
text = "action"
[node name="target_loc" type="Label" parent="VBoxContainer/closest"]
margin_top = 72.0
margin_right = 1024.0
margin_bottom = 86.0
text = "action"
[node name="path" type="Label" parent="VBoxContainer/closest"]
margin_top = 90.0
margin_right = 1024.0
margin_bottom = 104.0
text = "action"
[node name="path_point" type="Label" parent="VBoxContainer/closest"]
margin_top = 108.0
margin_right = 1024.0
margin_bottom = 122.0
text = "action"

View File

@@ -0,0 +1,99 @@
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _physics_process(delta):
for g in get_tree().get_nodes_in_group("agent"):
var bb = g
var space_state = g.get_world().direct_space_state
var up = Vector3(0, 1, 0)
var npc_pos = g.global_transform.origin
var front = -g.global_transform.basis[2]
var right = g.global_transform.basis[0]
var front_result = space_state.intersect_ray(npc_pos + up, npc_pos + up + front * 0.6,
[g], 0xffff)
bb.set("front_result", front_result)
var front_right_result = space_state.intersect_ray(npc_pos + up + right * 0.1, npc_pos + up + front * 0.8 + right * 0.3,
[g], 0xffff)
bb.set("front_right_result", front_right_result)
var front_left_result = space_state.intersect_ray(npc_pos + up - right * 0.1, npc_pos + up + front * 0.8 - right * 0.3,
[g], 0xffff)
bb.set("front_left_result", front_left_result)
var low_obstacle_result = space_state.intersect_ray(npc_pos + up * 0.3, npc_pos + up * 0.3 + front * 0.6,
[g], 0xffff)
bb.set("low_obstacle_result", low_obstacle_result)
for g in get_tree().get_nodes_in_group("agent"):
var bb = g
var front_result = bb.get("front_result")
var front_left_result = bb.get("front_left_result")
var front_right_result = bb.get("front_right_result")
var low_obstacle_result = bb.get("low_obstacle_result")
var front_col = false
var left_col = false
var right_col = false
var low_obstacle = false
if front_result.has("collider"):
var col = front_result.collider
if !col.is_in_group("entry"):
front_col = true
front_col = true
if front_left_result.has("collider"):
var col = front_left_result.collider
if !col.is_in_group("entry"):
left_col = true
left_col = true
if front_right_result.has("collider"):
var col = front_right_result.collider
if !col.is_in_group("entry"):
right_col = true
right_col = true
if !front_col:
if low_obstacle_result.has("collider"):
var col = low_obstacle_result.collider
if !col.is_in_group("entry"):
low_obstacle = true
# if left_col && right_col:
# if low_obstacle:
# npc.disable_gravity = true
# var c = [["set", "parameters/climb_low_obstacle/active", true]]
# npc.smart_obj(c)
var npc = g
var rot: Basis = npc.orientation.basis
if front_col:
var normal = front_result.normal
var xnormal = npc.global_transform.xform_inv(normal)
print("normal ", normal)
print("xnormal ", xnormal)
# var ok = false
# if xnormal.x < 0:
# rot = rot.rotated(Vector3(0, 1, 0), deg2rad(30 + 0.2 * (0.5 - randf())))
# ok = true
# elif xnormal.x > 0:
# rot = rot.rotated(Vector3(0, 1, 0), deg2rad(-30 + 0.2 * (0.5 - randf())))
# ok = true
if left_col && !right_col:
rot = rot.rotated(Vector3(0, 1, 0), deg2rad(-100 - 15.2 * (0.5 - randf())))
print("l")
elif right_col && !left_col:
rot = rot.rotated(Vector3(0, 1, 0), deg2rad(100 + 15.2 * (0.5 - randf())))
print("r")
elif right_col && left_col:
rot = rot.rotated(Vector3(0, 1, 0), npc.unp_fixup_angle)
# else:
# rot = rot.rotated(Vector3(0, 1, 0), deg2rad(10 + 10.0 * (0.5 - randf())))
var cur: Basis = npc.orientation.basis
cur = cur.slerp(rot, get_process_delta_time())
npc.orientation.basis = cur

View File

@@ -0,0 +1,223 @@
[gd_scene load_steps=11 format=2]
[ext_resource path="res://scenes/debug/agent.gd" type="Script" id=1]
[ext_resource path="res://scenes/debug/steering_test.gd" type="Script" id=2]
[sub_resource type="CapsuleShape" id=1]
radius = 0.5
[sub_resource type="CapsuleMesh" id=3]
radius = 0.5
[sub_resource type="SpatialMaterial" id=8]
albedo_color = Color( 0.509804, 0.188235, 0.188235, 1 )
[sub_resource type="SphereMesh" id=7]
material = SubResource( 8 )
radius = 0.1
height = 0.2
[sub_resource type="BoxShape" id=2]
extents = Vector3( 20, 0.5, 10 )
[sub_resource type="PlaneMesh" id=4]
size = Vector2( 40, 20 )
[sub_resource type="CubeMesh" id=5]
[sub_resource type="ConcavePolygonShape" id=6]
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
[node name="steering_test" type="Spatial"]
script = ExtResource( 2 )
[node name="agent" type="KinematicBody" parent="."]
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="agent"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 1, 0 )
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="agent"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 1, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="MeshInstance2" type="MeshInstance" parent="agent"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.554261 )
mesh = SubResource( 7 )
material/0 = null
[node name="agent2" type="KinematicBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1.85301 )
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="agent2"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 1, 0 )
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="agent2"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 1, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="MeshInstance2" type="MeshInstance" parent="agent2"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.554261 )
mesh = SubResource( 7 )
material/0 = null
[node name="agent3" type="KinematicBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.76611 )
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="agent3"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 1, 0 )
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="agent3"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 1, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="MeshInstance2" type="MeshInstance" parent="agent3"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.554261 )
mesh = SubResource( 7 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="."]
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0 )
shape = SubResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="StaticBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
mesh = SubResource( 4 )
material/0 = null
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.891481, 0.453057, 0, -0.453057, 0.891481, 0, 5, 3.608 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 25, 0 )
shadow_enabled = true
[node name="wall1" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -8.79885 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall1"]
[node name="CollisionShape" type="CollisionShape" parent="wall1/StaticBody"]
shape = SubResource( 6 )
[node name="wall2" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.04237, 1, -8.80032 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall2"]
[node name="CollisionShape" type="CollisionShape" parent="wall2/StaticBody"]
shape = SubResource( 6 )
[node name="wall9" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.08062, 1, -8.80032 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall9"]
[node name="CollisionShape" type="CollisionShape" parent="wall9/StaticBody"]
shape = SubResource( 6 )
[node name="wall10" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 6.101, 1, -8.80032 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall10"]
[node name="CollisionShape" type="CollisionShape" parent="wall10/StaticBody"]
shape = SubResource( 6 )
[node name="wall11" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 8.15713, 1, -6.77994 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall11"]
[node name="CollisionShape" type="CollisionShape" parent="wall11/StaticBody"]
shape = SubResource( 6 )
[node name="wall12" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 8.15713, 1, -4.74169 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall12"]
[node name="CollisionShape" type="CollisionShape" parent="wall12/StaticBody"]
shape = SubResource( 6 )
[node name="wall3" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.02011, 1, -7.45936 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall3"]
[node name="CollisionShape" type="CollisionShape" parent="wall3/StaticBody"]
shape = SubResource( 6 )
[node name="wall4" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.34319, 1, -5.41119 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall4"]
[node name="CollisionShape" type="CollisionShape" parent="wall4/StaticBody"]
shape = SubResource( 6 )
[node name="wall5" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.28132, 1, -3.52095 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall5"]
[node name="CollisionShape" type="CollisionShape" parent="wall5/StaticBody"]
shape = SubResource( 6 )
[node name="wall6" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.32278, 1, -3.39579 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall6"]
[node name="CollisionShape" type="CollisionShape" parent="wall6/StaticBody"]
shape = SubResource( 6 )
[node name="wall7" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.3049, 1, -1.39596 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall7"]
[node name="CollisionShape" type="CollisionShape" parent="wall7/StaticBody"]
shape = SubResource( 6 )
[node name="wall8" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.28648, 1, -1.539 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="wall8"]
[node name="CollisionShape" type="CollisionShape" parent="wall8/StaticBody"]
shape = SubResource( 6 )