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:
queuefree()
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 onSightRangebodyentered(body):
if body.isingroup("Player"):
state = ALERT
target = body
shoottimer.start()
func onSightRangebodyexited(body):
state = IDLE
shoottimer.stop()
func process(delta):
match state:
IDLE:
ap.play("Idle")
ALERT:
ap.play("Alert")
eyes.lookat(target.globaltransform.origin, Vector3.UP)
rotatey(deg2rad(eyes.rotation.y * turn_speed))
func onShootTimertimeout():
if raycast.iscolliding():
var hit = raycast.getcollider()
if hit.isin_group("Player"):
print("Hit!")