extends Node3D
@onready var ap = $AuxScene/AnimationPlayer
@onready var raycast = $RayCast3D
@onready var eyes = $eyes
@onready var nav = $NavigationAgent3D
const speed = 5
enum {
IDLE,
ALERT,
STUNND,
CHASING
}
var target
const T_S = 2
var state = IDLE
func _ready():
pass # Replace with function body.
func _process(delta):
match state:
IDLE:
ap.play("RifleIdle0")
ALERT:
ap.play("FiringRifle0")
eyes.look_at(target.global_transform.origin, Vector3.UP)
rotate_y(deg_to_rad(eyes.rotation.y * T_S))
var direction = (target.global_transform.origin - global_transform.origin).normalized()
CHASING:
ap.play("RifleRun0")
func _on_area_3d_body_entered(body):
if body.is_in_group("player"):
state = ALERT
target = body
func _on_area_3d_body_exited(body):
if body.is_in_group("player"):
state = CHASING
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter