我正在从事一个敌人的工作,该敌人使用简单的射线探测器,以发现参与者在他们面前,然后开始追捕参与者。 然而,我还是在运行时发现这一错误:“要求停职的团体是无主的。
该法典:
extends CharacterBody3D
var player = null
var health = 100
const SPEED = 4.0
const ATTACK_RANGE = 2.0
@export var player_path : NodePath
@onready var nav_agent = $NavigationAgent3D
@onready var view_ray = $MeshInstance3D/RayCast3D
var player_found = false
# Called when the node enters the scene tree for the first time.
func _ready():
player = get_node(player_path)
# Called every frame. delta is the elapsed time since the previous frame.
func _process(delta):
velocity = Vector3.ZERO
if(player_found == true):
nav_agent.set_target_position(player.global_transform.origin)
var next_nav_point = nav_agent.get_next_path_position()
velocity = (next_nav_point - global_transform.origin).normalized() * SPEED
look_at(Vector3(player.global_position.x, global_position.y, player.global_position.z), Vector3.UP)
if(player_found == false):
pass
if view_ray.get_collider().is_in_group("Player") and view_ray.get_collider() != null:
player_found = true
if view_ray.get_collider() == null:
player_found = false
move_and_slide()
func _target_in_range():
return global_position.distance_to(player.global_position) < ATTACK_RANGE
func _hit_finished():
if global_position.distance_to(player.global_position) < ATTACK_RANGE + 1.0:
var dir = global_position.direction_to(player.global_position)
player.hit(dir)
func hit():
health -= 33
if (health == 0 or health < 0):
queue_free()
这里的结构是:
VC_scout
MeshInstance3D
RayCast3D
CollisionShape3D
NavigationAgent3D
事先感谢你!