conforms file names to consistant standard
This commit is contained in:
20
scripts/enemy_ai/beelining_controller.gd
Normal file
20
scripts/enemy_ai/beelining_controller.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
class_name BeeliningController
|
||||
extends EnemyMovement
|
||||
|
||||
var goal: Node3D
|
||||
var direction: Vector3
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
if goal:
|
||||
distance_remaining = character.global_position.distance_to(goal.global_position)
|
||||
direction = character.global_position.direction_to(goal.global_position)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if !direction:
|
||||
return
|
||||
var distance_travelled: float = (character.stats.movement_speed * clampf(character.movement_speed_penalty, 0.0, 1.0)) * delta
|
||||
distance_remaining -= distance_travelled
|
||||
character.global_position = character.global_position + (direction * distance_travelled)
|
||||
1
scripts/enemy_ai/beelining_controller.gd.uid
Normal file
1
scripts/enemy_ai/beelining_controller.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d147vuqksqhis
|
||||
13
scripts/enemy_ai/enemy_movement.gd
Normal file
13
scripts/enemy_ai/enemy_movement.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
class_name EnemyMovement
|
||||
extends Node
|
||||
|
||||
@export var character: EnemyController
|
||||
|
||||
var distance_remaining: float = 0.0
|
||||
var speed: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var variance: float = NoiseRandom.randf_in_range(character.name.to_int(), -1.0, 1.0)
|
||||
var variance_max: float = 0.03 # Enemy speed can vary by 3% from their base speed
|
||||
speed = character.stats.movement_speed + (variance * variance_max)
|
||||
1
scripts/enemy_ai/enemy_movement.gd.uid
Normal file
1
scripts/enemy_ai/enemy_movement.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cy0htr7710hnn
|
||||
168
scripts/enemy_ai/leaping_controller.gd
Normal file
168
scripts/enemy_ai/leaping_controller.gd
Normal file
@@ -0,0 +1,168 @@
|
||||
class_name LeapingController
|
||||
extends PathingController
|
||||
|
||||
@export var eastl: Label
|
||||
@export var westl: Label
|
||||
@export var northl: Label
|
||||
@export var southl: Label
|
||||
@export var easts: Sprite3D
|
||||
@export var wests: Sprite3D
|
||||
@export var norths: Sprite3D
|
||||
@export var souths: Sprite3D
|
||||
@export var box: CSGBox3D
|
||||
@export var tol: Label
|
||||
@export var jump_distance: float = 4.0
|
||||
|
||||
var tolerance: float = 50.0
|
||||
var jumping: bool = false
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
tolerance = remap(character.health.current_health, character.health.max_health * 0.20, character.health.max_health, 10, 50)
|
||||
tolerance = maxf(tolerance, 10)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if !next_node or jumping:
|
||||
return
|
||||
walk(delta)
|
||||
consider_leap(Vector3.FORWARD)
|
||||
consider_leap(Vector3.LEFT)
|
||||
consider_leap(Vector3.BACK)
|
||||
consider_leap(Vector3.RIGHT)
|
||||
#var closest_point: int = astar.astar.get_closest_point(character.global_position, false)
|
||||
#box.global_position = astar.astar.get_point_position(closest_point)
|
||||
#var east: int = astar.get_east_point(closest_point)
|
||||
#var west: int = astar.get_west_point(closest_point)
|
||||
#var north: int = astar.get_north_point(closest_point)
|
||||
#var south: int = astar.get_south_point(closest_point)
|
||||
#if east >= 0 and astar.astar.is_point_disabled(east):
|
||||
#eastl.text = "fuck no"
|
||||
#else:
|
||||
#eastl.text = "yeah"
|
||||
#if west >= 0 and astar.astar.is_point_disabled(west):
|
||||
#westl.text = "fuck no"
|
||||
#else:
|
||||
#westl.text = "yeah"
|
||||
#if north >= 0 and astar.astar.is_point_disabled(north):
|
||||
#northl.text = "fuck no"
|
||||
#else:
|
||||
#northl.text = "yeah"
|
||||
#if south >= 0 and astar.astar.is_point_disabled(south):
|
||||
#southl.text = "fuck no"
|
||||
#else:
|
||||
#southl.text = "yeah"
|
||||
#norths.global_position = character.global_position + Vector3(-1.0, 1.0, 0.0)
|
||||
#souths.global_position = character.global_position + Vector3(1.0, 1.0, 0.0)
|
||||
#easts.global_position = character.global_position + Vector3(0.0, 1.0, -1.0)
|
||||
#wests.global_position = character.global_position + Vector3(0.0, 1.0, 1.0)
|
||||
|
||||
|
||||
|
||||
#if east >= 0:
|
||||
#if astar.astar.is_point_disabled(east):
|
||||
#var further_point: int = astar.get_east_point(east)
|
||||
#if further_point >= 0 and !astar.astar.is_point_disabled(further_point):
|
||||
#var expected_offset: float = path.get_closest_offset(character.global_position + Vector3(0.0, 0.0, -4.0))
|
||||
#var current_offset: float = path.get_closest_offset(character.global_position)
|
||||
#var gain: float = expected_offset - current_offset
|
||||
#if gain >= tolerance:
|
||||
#distance_remaining -= gain
|
||||
##path_progress += gain
|
||||
#leap(Vector3(0.0, 0.0, -4.0))
|
||||
#eastl.text = str(gain)
|
||||
##easts.visible = true
|
||||
#else:
|
||||
#eastl.text = "cant"
|
||||
#else:
|
||||
#eastl.text = "clear"
|
||||
#else:
|
||||
#eastl.text = "invalid"
|
||||
#if west >= 0:
|
||||
#if astar.astar.is_point_disabled(west):
|
||||
#var further_point: int = astar.get_west_point(west)
|
||||
#if further_point >= 0 and !astar.astar.is_point_disabled(further_point):
|
||||
#var expected_offset: float = path.get_closest_offset(character.global_position + Vector3(0.0, 0.0, 4.0))
|
||||
#var current_offset: float = path.get_closest_offset(character.global_position)
|
||||
#var gain: float = expected_offset - current_offset
|
||||
#if gain >= tolerance:
|
||||
#distance_remaining -= gain
|
||||
##path_progress += gain
|
||||
#leap(Vector3(0.0, 0.0, 4.0))
|
||||
#westl.text = str(gain)
|
||||
##wests.visible = true
|
||||
#else:
|
||||
#westl.text = "cant"
|
||||
#else:
|
||||
#westl.text = "clear"
|
||||
#else:
|
||||
#westl.text = "invalid"
|
||||
#if north >= 0:
|
||||
#if astar.astar.is_point_disabled(north):
|
||||
#var further_point: int = astar.get_north_point(north)
|
||||
#if further_point >= 0 and !astar.astar.is_point_disabled(further_point):
|
||||
#var expected_offset: float = path.get_closest_offset(character.global_position + Vector3(-4.0, 0.0, 0.0))
|
||||
#var current_offset: float = path.get_closest_offset(character.global_position)
|
||||
#var gain: float = expected_offset - current_offset
|
||||
#if gain >= tolerance:
|
||||
#distance_remaining -= gain
|
||||
##path_progress += gain
|
||||
#leap(Vector3(-4.0, 0.0, 0.0))
|
||||
#northl.text = str(gain)
|
||||
##norths.visible = true
|
||||
#else:
|
||||
#northl.text = "cant"
|
||||
#else:
|
||||
#northl.text = "clear"
|
||||
#else:
|
||||
#northl.text = "invalid"
|
||||
#if south >= 0:
|
||||
#if astar.astar.is_point_disabled(south):
|
||||
#var further_point: int = astar.get_south_point(south)
|
||||
#if further_point >= 0 and !astar.astar.is_point_disabled(further_point):
|
||||
#var expected_offset: float = path.get_closest_offset(character.global_position + Vector3(4.0, 0.0, 0.0))
|
||||
#var current_offset: float = path.get_closest_offset(character.global_position)
|
||||
#var gain: float = expected_offset - current_offset
|
||||
#if gain >= tolerance:
|
||||
#distance_remaining -= gain
|
||||
##path_progress += gain
|
||||
#leap(Vector3(4.0, 0.0, 0.0))
|
||||
#southl.text = str(gain)
|
||||
##souths.visible = true
|
||||
#else:
|
||||
#southl.text = "cant"
|
||||
#else:
|
||||
#southl.text = "clear"
|
||||
#else:
|
||||
#southl.text = "invalid"
|
||||
|
||||
|
||||
func consider_leap(direction: Vector3) -> void:
|
||||
var node: FlowNodeData = check_jump(character.global_position + (direction * jump_distance))
|
||||
if node:
|
||||
var expected_distance_remaining: float = calculate_distance_to_goal(node)
|
||||
expected_distance_remaining += (character.global_position + (direction * jump_distance)).distance_to(node.global_position)
|
||||
var gain: float = distance_remaining - expected_distance_remaining
|
||||
if gain >= tolerance:
|
||||
distance_remaining -= gain
|
||||
leap(direction * jump_distance)
|
||||
next_node = node
|
||||
|
||||
|
||||
func finish_jump() -> void:
|
||||
jumping = false
|
||||
|
||||
|
||||
func check_jump(destination: Vector3) -> FlowNodeData:
|
||||
var closest_point: FlowNodeData = flow_field.get_closest_point(destination, true, false)
|
||||
if !closest_point.best_path or closest_point.global_position.distance_to(destination) > 1.2:
|
||||
return null
|
||||
return closest_point.best_path
|
||||
|
||||
|
||||
func leap(to_point: Vector3) -> void:
|
||||
jumping = true
|
||||
var tween: Tween = create_tween()
|
||||
tween.tween_property(character, "global_position", character.global_position + (to_point / 2.0) + Vector3.UP, 0.3)
|
||||
tween.tween_property(character, "global_position", character.global_position + to_point, 0.3)
|
||||
tween.tween_callback(finish_jump)
|
||||
1
scripts/enemy_ai/leaping_controller.gd.uid
Normal file
1
scripts/enemy_ai/leaping_controller.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dqluvn05min37
|
||||
71
scripts/enemy_ai/pathing_controller.gd
Normal file
71
scripts/enemy_ai/pathing_controller.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
class_name PathingController
|
||||
extends EnemyMovement
|
||||
|
||||
var random_points_generated: int
|
||||
var flow_field: FlowField
|
||||
var next_node: FlowNodeData :
|
||||
get():
|
||||
return next_node
|
||||
set(value):
|
||||
next_node = value
|
||||
if next_node == null:
|
||||
return
|
||||
var found_point: bool = false
|
||||
while !found_point:
|
||||
random_points_generated += 1
|
||||
var sample: int = random_points_generated + character.name.to_int()
|
||||
var r: float = 1.0 * sqrt(NoiseRandom.randf_in_range(sample, 0.0, 1.0))
|
||||
var theta: float = NoiseRandom.randf_in_range(sample * 4, 0.0, 1.0) * 2.0 * PI
|
||||
var x: float = r * cos(theta)
|
||||
var y: float = r * sin(theta)
|
||||
if Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y).distance_to(next_node.position) <= 1.0:
|
||||
found_point = true
|
||||
next_pos = Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y)
|
||||
var next_pos: Vector3
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
if flow_field:
|
||||
next_node = flow_field.get_closest_point(character.global_position, true, false)
|
||||
#We skip one node so the "start" nodes placed near
|
||||
#spawners are just usefull for "catching" enemies that are looking
|
||||
#for a way into the pathfinding graph
|
||||
next_node = next_node.best_path
|
||||
distance_remaining += calculate_distance_to_goal(next_node)
|
||||
|
||||
|
||||
func calculate_distance_to_goal(node: FlowNodeData) -> float:
|
||||
var distance: float = 0.0
|
||||
distance += character.global_position.distance_to(node.position)
|
||||
if node.best_path:
|
||||
var then_next_node: FlowNodeData = node.best_path
|
||||
distance += node.position.distance_to(then_next_node.position)
|
||||
while then_next_node.best_path:
|
||||
distance += then_next_node.position.distance_to(then_next_node.best_path.position)
|
||||
then_next_node = then_next_node.best_path
|
||||
return distance
|
||||
|
||||
|
||||
func walk(delta: float) -> void:
|
||||
var distance_travelled: float = (speed * clampf(speed, 0.0, 1.0)) * delta
|
||||
distance_remaining -= distance_travelled
|
||||
character.global_position = character.global_position.move_toward(next_pos, distance_travelled)
|
||||
var distance_to_next_pos: float = character.global_position.distance_to(next_pos)
|
||||
if distance_to_next_pos <= 0.05:
|
||||
next_node = next_node.best_path
|
||||
else:
|
||||
character.look_at(next_pos)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
#if !path:
|
||||
# return
|
||||
if !next_node:
|
||||
return
|
||||
walk(delta)
|
||||
#path_progress += distance_travelled
|
||||
#var sample: Transform3D = path.sample_baked_with_rotation(path_progress, true)
|
||||
#character.global_position = sample.origin
|
||||
#character.look_at(character.global_position + -sample.basis.z)
|
||||
#var closest_point: Vector3 = path.get_closest_point(character.global_position)
|
||||
1
scripts/enemy_ai/pathing_controller.gd.uid
Normal file
1
scripts/enemy_ai/pathing_controller.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b62xnsbki8axa
|
||||
Reference in New Issue
Block a user