|
|
|
|
@ -24,6 +24,40 @@ func raycast_wall(from:Vector3,to:Vector3) -> bool:
|
|
|
|
|
var result = space_state.intersect_ray(query)
|
|
|
|
|
return result.size()>0
|
|
|
|
|
|
|
|
|
|
func attack_detection(pos:Vector3,target_pos:Vector3,target_radius:float,target_height:float,attack_dir:Vector2,attack_height:float,attack_size:Vector2,attack_radius:float) -> bool:
|
|
|
|
|
# 检查Y
|
|
|
|
|
var attack_y_min = pos.y
|
|
|
|
|
var attack_y_max = pos.y + attack_height
|
|
|
|
|
var target_y_min = target_pos.y
|
|
|
|
|
var target_y_max = target_pos.y + target_height
|
|
|
|
|
if attack_y_min > target_y_max || attack_y_max < target_y_min:
|
|
|
|
|
return false
|
|
|
|
|
# 保底距离
|
|
|
|
|
if pos.distance_to(target_pos) < 0.01:
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
# 2d距离
|
|
|
|
|
var dist_2d = Vector2(pos.x,pos.z).distance_to(Vector2(target_pos.x,target_pos.z))
|
|
|
|
|
|
|
|
|
|
# 如果是圆形
|
|
|
|
|
if attack_radius:
|
|
|
|
|
return dist_2d <= attack_radius + target_radius
|
|
|
|
|
|
|
|
|
|
# 旋转target
|
|
|
|
|
var angle = attack_dir.angle_to(Vector2.RIGHT)
|
|
|
|
|
target_pos = target_pos - pos
|
|
|
|
|
target_pos = target_pos.rotated(Vector3.UP,angle)
|
|
|
|
|
|
|
|
|
|
var dist_x = abs(target_pos.x) - attack_size.x
|
|
|
|
|
var dist_y = abs(target_pos.z) - attack_size.y
|
|
|
|
|
|
|
|
|
|
if dist_x <= target_radius && dist_y <= target_radius:
|
|
|
|
|
if (dist_x <= 0 || dist_y <= 0):
|
|
|
|
|
return true
|
|
|
|
|
var dist_squared = pow(dist_x, 2) + pow(dist_y, 2)
|
|
|
|
|
return dist_squared <= pow(target_radius, 2)
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
func refresh_animation_lib():
|
|
|
|
|
var animation_library_path = "res://resource/skill_animation_library/animation_library.tres"
|
|
|
|
|
var animation_library = load(animation_library_path)
|
|
|
|
|
|