32 lines
1.0 KiB
GDScript
32 lines
1.0 KiB
GDScript
@tool
|
|
extends BTAction
|
|
|
|
@export var target_node_var: StringName = &"target_node"
|
|
|
|
const RAY_OFFSET:Vector3 = Vector3.UP * 0.5
|
|
|
|
var _physics_ray_query_parameters:PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.new()
|
|
|
|
func _generate_name() -> String:
|
|
return "CheckNodeVisible(%s)" % [
|
|
LimboUtility.decorate_var(target_node_var)
|
|
]
|
|
|
|
func _tick(_delta: float) -> Status:
|
|
var target_node:Node3D = blackboard.get_var(target_node_var)
|
|
|
|
var agent_node:Node3D = agent as Node3D
|
|
var world_space_state:PhysicsDirectSpaceState3D = agent_node.get_world_3d().direct_space_state
|
|
|
|
var source_position:Vector3 = agent_node.global_position + RAY_OFFSET
|
|
var target_position:Vector3 = target_node.global_position + RAY_OFFSET
|
|
_physics_ray_query_parameters.from = source_position
|
|
_physics_ray_query_parameters.to = target_position
|
|
_physics_ray_query_parameters.collision_mask = 32 + 1
|
|
var result:Dictionary = world_space_state.intersect_ray(_physics_ray_query_parameters)
|
|
|
|
if result.is_empty():
|
|
return SUCCESS
|
|
|
|
return FAILURE
|