-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inspector.gd
91 lines (63 loc) · 2.57 KB
/
Inspector.gd
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
extends KinematicBody
signal detectedPlayer
export (float) var gravity = 10
var next_move_change = 0
var move_vector = Vector3(0.0, 0.0, 0.0)
var rotation_helper
var sight_ray_caster
const MOVE_SPEED = 5
const DEFAULT_TIME_BETWEEN_MOVES = 5000
var seen_player_object = null
var time_until_next_audio = 0
func _ready():
rotation_helper = $RotationHelper
sight_ray_caster = $RotationHelper/SightRay
func _process(delta):
var current_time = OS.get_ticks_msec()
if !is_on_floor():
move_vector.y -= gravity*delta
if current_time - next_move_change > 0:
next_move_change = current_time + DEFAULT_TIME_BETWEEN_MOVES + randi() % 5000 - 2500
move_vector = Vector3(0.0, 0.0, 0.0)
if randi() % 2 == 0:
move_vector += Vector3(1.0, 0.0, 0.0)
if randi() % 2 == 0:
move_vector += Vector3(-1.0, 0.0, 0.0)
if randi() % 2 == 0:
move_vector += Vector3(0.0, 0.0, 1.0)
if randi() % 2 == 0:
move_vector += Vector3(0.0, 0.0, -1.0)
move_vector = move_vector.normalized()
if move_vector.length() != 0:
var angle = Vector2(0, 1).angle_to(Vector2(move_vector.x, move_vector.z))
rotation_helper.set_rotation(Vector3(PI / 2,-angle,0))
move_and_slide(move_vector * MOVE_SPEED, Vector3(0.0, 1.0, 0.0))
if sight_ray_caster.is_colliding():
var seen_object = sight_ray_caster.get_collider()
if seen_object.is_in_group("player"):
emit_signal("detectedPlayer")
point_raycaster_to_player()
play_sound(delta)
func play_sound(delta):
var current_time = OS.get_unix_time()
time_until_next_audio -= delta * 1000
if time_until_next_audio <= 0:
var which_sound = randi() % 3
if which_sound == 0:
$ThroatClearing.play()
elif which_sound == 1:
$Whisle.play()
else:
$Hmm.play()
time_until_next_audio = 5000 + (randi() % 5000)
func point_raycaster_to_player():
if seen_player_object != null:
var player_position = seen_player_object.rotation_helper.to_global(seen_player_object.rotation_helper.get_translation())
sight_ray_caster.set_cast_to(rotation_helper.to_local(player_position) + Vector3(0.0, 0.0, -1.0))
func _on_InspectionArea_body_entered(body):
if body.is_in_group("player"):
seen_player_object = body
func _on_InspectionArea_body_exited(body):
if body.is_in_group("player"):
seen_player_object = null
sight_ray_caster.set_cast_to(Vector3(10.0, 1.0, 0.0))