-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayerDetection.gd
More file actions
54 lines (36 loc) · 1.29 KB
/
Copy pathPlayerDetection.gd
File metadata and controls
54 lines (36 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extends "res://Scripts/Character.gd"
const FOV_TOLERANCE = 20
const MAX_DETECTION_RANGE = 230
const RED = Color(1, .25, .25)
const WHITE = Color(1, 1, 1)
onready var Player = Global.Player
func _ready():
add_to_group("npc")
func _process(delta):
if Player_is_in_FOV_TOLERANCE() and Player_is_in_LOS():
$Torch.color = RED
get_tree().call_group("SuspicionMeter", "player_seen")
else:
$Torch.color = WHITE
func Player_is_in_FOV_TOLERANCE():
var NPC_facing_direction = Vector2(1,0).rotated(global_rotation)
var direction_to_Player = (Global.Player.position - global_position).normalized()
if abs(direction_to_Player.angle_to(NPC_facing_direction)) < deg2rad(FOV_TOLERANCE):
return true
else:
return false
func Player_is_in_LOS():
var space = get_world_2d().direct_space_state
var LOS_obstacle = space.intersect_ray(global_position, Global.Player.global_position, [self], collision_mask)
if not LOS_obstacle:
return false
var distance_to_player = Global.Player.global_position.distance_to(global_position)
var Player_in_range = distance_to_player < MAX_DETECTION_RANGE
if LOS_obstacle.collider == Global.Player and Player_in_range:
return true
else:
return false
func NightVision_mode():
$Torch.enabled = false
func DarkVision_mode():
$Torch.enabled = true