Added stairs (can't climb yet).

This commit is contained in:
Segey Lapin
2020-04-13 18:18:07 +03:00
parent c9860ae759
commit 88e8359f64
9 changed files with 1836 additions and 52 deletions

View File

@@ -2,7 +2,7 @@ extends Node
signal spawn_player(pos)
signal spawn_npc(xform)
enum states {STATE_PREINIT, STATE_INIT, STATE_EXECUTE, STATE_SLEEP}
enum states {STATE_PREINIT, STATE_INIT, STATE_INIT_ASTAR, STATE_EXECUTE, STATE_SLEEP}
var state = states.STATE_PREINIT
var astar = null
@@ -113,13 +113,20 @@ func spawn_characters():
print("npc")
emit_signal("spawn_npc", e)
var path_nodes = []
var endings = []
var connections = {}
func _physics_process(delta):
match state:
states.STATE_INIT:
print("starting AI")
var endings = []
var connections = {}
for e in get_tree().get_nodes_in_group("path"):
path_nodes = get_tree().get_nodes_in_group("path")
endings = []
connections = {}
state = states.STATE_INIT_ASTAR
states.STATE_INIT_ASTAR:
if path_nodes.size() > 0:
var e = path_nodes.pop_front()
print(e.name)
var new_points = Array(e.curve.get_baked_points())
var new_ids = []
@@ -145,39 +152,25 @@ func _physics_process(delta):
astar.connect_points(new_ids[s], new_ids[s + 1])
connections[new_ids[s]] = new_ids[s + 1]
connections[new_ids[s + 1]] = new_ids[s]
print("path nodes passed")
var space_state = get_parent().get_world().direct_space_state
for id1 in endings:
for id2 in endings:
if id1 == id2:
continue
if astar.are_points_connected(id1, id2):
continue
var p0 = astar.get_point_position(id1)
var p1 = astar.get_point_position(id2)
var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.5, 0), p1 + Vector3(0, 0.5, 0), [], 0x1)
if !front_result.has("collider"):
astar.connect_points(id1, id2)
# for pk in connections.keys():
# var id1 = pk
# var id2 = connections[pk]
# if astar.are_points_connected(id1, id2):
# var p0 = astar.get_point_position(id1)
# var p1 = astar.get_point_position(id2)
# var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.8, 0), p1 + Vector3(0, 0.8, 0), [], 0x1)
# if front_result.has("collider"):
# var collider = front_result.collider
# var ok = false
# if collider.is_in_group("furniture"):
# ok = true
# elif collider.is_in_group("door"):
# ok = true
# astar.disconnect_points(id1, id2)
print("astar complete")
spawn_characters()
print("characters spawned")
$blackboard.set("metaai", self)
state = states.STATE_EXECUTE
else:
print("path nodes passed")
var space_state = get_parent().get_world().direct_space_state
for id1 in endings:
for id2 in endings:
if id1 == id2:
continue
if astar.are_points_connected(id1, id2):
continue
var p0 = astar.get_point_position(id1)
var p1 = astar.get_point_position(id2)
var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.5, 0), p1 + Vector3(0, 0.5, 0), [], 0x1)
if !front_result.has("collider"):
astar.connect_points(id1, id2)
print("astar complete")
spawn_characters()
print("characters spawned")
$blackboard.set("metaai", self)
state = states.STATE_EXECUTE
states.STATE_EXECUTE:
if randf() > 0.7:
calc_visible_lists()
@@ -227,7 +220,7 @@ func _physics_process(delta):
for r in npc_raycasts:
if r.has("radius"):
var shape : = SphereShape.new()
shape.radius
shape.radius = r.radius
var query = PhysicsShapeQueryParameters.new()
query.set_shape(query)
query.collision_mask = r.mask