Adds enemies
This commit is contained in:
parent
cf8ba8bacb
commit
76e5b1927f
324 changed files with 28447 additions and 106 deletions
49
scripts/enemies/enemy_ai.gd
Normal file
49
scripts/enemies/enemy_ai.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
extends BTPlayer
|
||||
|
||||
class_name EnemyAI
|
||||
|
||||
const ROAM_DISTANCE: float = 10.0
|
||||
const DISTANCE_TO_PLAYER: float = 10.0
|
||||
|
||||
@export var character: CharacterBody3D
|
||||
|
||||
@export_category("Sprite")
|
||||
@export var sprite:Sprite3D;
|
||||
@export var idleTexture: Texture2D;
|
||||
@export var aggressiveTexture: Texture2D;
|
||||
|
||||
@export_category("Agents")
|
||||
@export var agent: NavigationAgent3D;
|
||||
|
||||
@export var animationTree: AnimationTree;
|
||||
|
||||
@export_category("Firing")
|
||||
@export var MuzzleFlash: PackedScene
|
||||
@export var Origin: Node3D
|
||||
|
||||
var aggressive = false
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
self.blackboard.set_var('PlayerDistance', character.global_position.distance_to(Player.Instance.global_position))
|
||||
self.blackboard.set_var('LookingAngleToPlayer', (-character.global_basis.z).dot((character.global_position - Player.Instance.global_position).normalized()))
|
||||
|
||||
func setAggressive(value: bool) -> void:
|
||||
if not aggressive && value:
|
||||
agent.target_position = character.global_position;
|
||||
|
||||
sprite.texture = aggressiveTexture if value else idleTexture
|
||||
aggressive = value
|
||||
|
||||
|
||||
func roam() -> void:
|
||||
var targetPosition = character.global_position + (Vector3(randf_range(-1, 1), randf_range(-1, 1), randf_range(-1,1)).normalized() * randf_range(0, ROAM_DISTANCE))
|
||||
agent.target_position = targetPosition
|
||||
|
||||
func moveToPlayer() -> void:
|
||||
var toPlayerDirection = Player.Instance.global_position - character.global_position
|
||||
agent.target_position = Player.Instance.global_position + toPlayerDirection.normalized() * -DISTANCE_TO_PLAYER
|
||||
|
||||
func Fire() -> void:
|
||||
self.animationTree['parameters/playback'].travel('Fire')
|
||||
var instance = MuzzleFlash.instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
|
||||
Origin.add_child(instance)
|
||||
Loading…
Add table
Add a link
Reference in a new issue