proto3 initial commit
This commit is contained in:
26
proto3/godot/ai/can_grab.gd
Normal file
26
proto3/godot/ai/can_grab.gd
Normal file
@@ -0,0 +1,26 @@
|
||||
extends BTCondition
|
||||
class_name BTCanGrab
|
||||
|
||||
func tick(tick: Tick) -> int:
|
||||
var npc = tick.actor
|
||||
var bb = tick.blackboard
|
||||
if !npc.is_in_group("guard"):
|
||||
return FAILED
|
||||
if npc.get_meta("action") == "forcing":
|
||||
return FAILED
|
||||
var enemy = bb.get("closest_enemy")
|
||||
if !enemy:
|
||||
return FAILED
|
||||
var enemy_pos = enemy.global_transform.origin
|
||||
var npc_pos = npc.global_transform.origin
|
||||
var space_state = npc.get_world().direct_space_state
|
||||
var result
|
||||
var up = npc.orientation.basis[1] * 0.9
|
||||
var dir = (enemy_pos - npc_pos).normalized() * 1.2
|
||||
result = space_state.intersect_ray(npc_pos + up, npc_pos + dir + up,
|
||||
[npc], 0xffff)
|
||||
if result.has("collider"):
|
||||
if result.collider == enemy:
|
||||
return OK
|
||||
return FAILED
|
||||
|
||||
Reference in New Issue
Block a user