Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dingus04 |
So i followed Garbaj’s Enemy AI 1 and 2 and i now want to make the enemy have a death thing
The Enemy scene has an instance of the model scene and the model scene has the anim player and this script;
extends KinematicBody
var health = 100
onready var AP = $AnimationPlayer
#onready var dt = $Death
func _process(delta):
if health <= 0:
queue_free()
When queue_free happens i get;
Attempt to call function ‘play’ in base ‘previously freed instance’ on a null instance.
On the scene of the enemy here is all of its code;
extends Spatial
enum{
IDLE,
ALERT,
Dead,
}
var state = IDLE
var target
#var health = 2
const turn_speed = 2
onready var raycast =$RayCast
onready var ap = $dummymale/AnimationPlayer
onready var eyes = $Eyes
onready var shoottimer = $ShootTimer
func _on_SightRange_body_entered(body):
if body.is_in_group(“Player”):
state = ALERT
target = body
shoottimer.start()
func _on_SightRange_body_exited(body):
state = IDLE
shoottimer.stop()
func _process(delta):
match state:
IDLE:
ap.play(“Idle”)
ALERT:
ap.play(“Alert”)
eyes.look_at(target.global_transform.origin, Vector3.UP)
rotate_y(deg2rad(eyes.rotation.y * turn_speed))
func _on_ShootTimer_timeout():
if raycast.is_colliding():
var hit = raycast.get_collider()
if hit.is_in_group(“Player”):
print(“Hit!”)