Implermented health
This commit is contained in:
parent
76e5b1927f
commit
e6391d9fdd
13 changed files with 142 additions and 109 deletions
|
|
@ -7,6 +7,7 @@ const MOVEMENT_SPEED = 1
|
|||
@onready var agent:NavigationAgent3D = $NavigationAgent
|
||||
@onready var enemyAi: EnemyAI = $BTPlayer
|
||||
@onready var health: Health = $Health
|
||||
@onready var origin: Node3D = $"enemies/Vert/Shoot Marker"
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
|
@ -43,7 +44,27 @@ func _physics_process(delta: float) -> void:
|
|||
if enemyAi.aggressive:
|
||||
rotateTo(delta, (Player.Instance.global_position - self.global_position).normalized())
|
||||
else:
|
||||
rotateTo(delta, -velocity.normalized())
|
||||
rotateTo(delta, velocity.normalized())
|
||||
|
||||
updateMovementBlend(delta, velocity.length())
|
||||
self.animationtree['parameters/Movement/blend_position'] = movementBlend
|
||||
|
||||
func fireWeapon() -> void:
|
||||
var fireDirection = (Player.Instance.enemyTarget.global_position - origin.global_position).normalized()
|
||||
fireDirection = fireDirection.rotated(Vector3.UP, randf_range(-.3, .3))
|
||||
|
||||
DebugDraw3D.draw_arrow(origin.global_position, origin.global_position + Vector3.UP * 1, Color.RED, 0.5, true, 10)
|
||||
DebugDraw3D.draw_arrow(origin.global_position, origin.global_position + fireDirection * 10, Color.WHITE, 0.5, true, 10)
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.create(origin.global_position, origin.global_position + fireDirection * 200)
|
||||
var result = get_world_3d().direct_space_state.intersect_ray(query)
|
||||
|
||||
if not result:
|
||||
return
|
||||
|
||||
var health = result.collider.get_node_or_null('Health')
|
||||
print(health)
|
||||
if not health:
|
||||
return
|
||||
|
||||
result.collider.health.take_damage(1, Vector2(0,0))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class_name EnemyAI
|
|||
const ROAM_DISTANCE: float = 10.0
|
||||
const DISTANCE_TO_PLAYER: float = 10.0
|
||||
|
||||
@export var character: CharacterBody3D
|
||||
@export var character: Enemy
|
||||
|
||||
@export_category("Sprite")
|
||||
@export var sprite:Sprite3D;
|
||||
|
|
@ -14,7 +14,6 @@ const DISTANCE_TO_PLAYER: float = 10.0
|
|||
|
||||
@export_category("Agents")
|
||||
@export var agent: NavigationAgent3D;
|
||||
|
||||
@export var animationTree: AnimationTree;
|
||||
|
||||
@export_category("Firing")
|
||||
|
|
@ -47,3 +46,5 @@ func Fire() -> void:
|
|||
self.animationTree['parameters/playback'].travel('Fire')
|
||||
var instance = MuzzleFlash.instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
|
||||
Origin.add_child(instance)
|
||||
character.fireWeapon()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue