-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.tscn
356 lines (279 loc) · 10.7 KB
/
Player.tscn
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
[gd_scene load_steps=12 format=2]
[ext_resource path="res://Flying Gun.tscn" type="PackedScene" id=1]
[ext_resource path="res://Models/humanoid.dae" type="PackedScene" id=2]
[ext_resource path="res://Player Hand.tscn" type="PackedScene" id=3]
[ext_resource path="res://Sprites/xhairs/crosshair012.png" type="Texture" id=4]
[ext_resource path="res://Audio/AirSwish1.wav" type="AudioStream" id=5]
[ext_resource path="res://Materials.tscn" type="PackedScene" id=6]
[sub_resource type="PhysicsMaterial" id=1]
friction = 0.97
[sub_resource type="GDScript" id=2]
script/source = "extends RigidBody
export(float, 0, 100) var max_move_speed = 1
export(float, 0, 100) var accel_speed = 1
export(float, 0, 2) var mouse_sensitivity_x = 1
export(float, 0, 2) var mouse_sensitivity_y = 1
export(float, 0, 200) var joy_aim_sensitivity_x = 1
export(float, 0, 200) var joy_aim_sensitivity_y = 1
export(float, 0, 1000) var gun_speed = 1
export(float, 0, 100) var jump_force = 1
export(bool) var is_level_1
var count_down = 2
var stop_factor = 0.88
export(PackedScene) var gun_projectile
var desiredMoveVector = Vector2()
var yaw : Spatial
var pitch : Spatial
var look : RayCast
var targetGun : RayCast
var shotGun
var camera : Camera
var try_jump = false
var anim : AnimationTree
var preventSpawning : Area
var canThrow : bool
var throwGun_sound
var hasGun : bool = true
var level1PickedUpGun = false
var level1AnimationShown = false
func _ready():
camera = find_node(\"Camera\")
yaw = get_node(\"Yaw\")
pitch = get_node(\"Yaw/Pitch\")
look = find_node(\"Look\")
targetGun = find_node(\"Target Gun\")
throwGun_sound = get_node(\"throwGun\")
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
anim = get_node(\"Yaw/Pitch/Player Hand/Armature/AnimationTree\")
preventSpawning = get_node(\"Yaw/Pitch/Gun Spawn Position/Prevent Spawning\")
startAnimation()
yield(get_tree(), \"idle_frame\")
$Materials.hide()
func startAnimation():
if is_level_1:
anim.tree_root.set_start_node(\"HandOut\")
hasGun = false
find_node(\"Gun\").visible = false
get_node(\"/root/Game\").showBigText(\"GET YOUR GUN\")
else:
anim.tree_root.set_start_node(\"HoldGunBarrel\")
func _input(event):
var mouseMode = Input.get_mouse_mode()
if (event.is_action_pressed(\"escape\")):
get_node(\"/root/Game\").start_over()
get_tree().set_input_as_handled()
func _unhandled_input(event):
var mouseMode = Input.get_mouse_mode()
if (event.is_action_pressed(\"fire\")):
if (mouseMode != Input.MOUSE_MODE_CAPTURED):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
return
fire_or_return(false)
if (event.is_action_pressed(\"fire_alt\")):
fire_or_return(true)
pass
if (event.is_action_pressed(\"jump\")):
try_jump = true
pass
if (event is InputEventMouseMotion and mouseMode == Input.MOUSE_MODE_CAPTURED):
move_aim(event.relative.x * mouse_sensitivity_x, event.relative.y * mouse_sensitivity_y)
func move_aim(x, y):
yaw.set_transform(yaw.get_transform().rotated(Vector3.UP, deg2rad(-x)).orthonormalized())
if pitch.get_transform().basis.get_euler().x < PI / 2 and y > 0:
pitch.set_transform( pitch.get_transform() \\
.rotated(pitch.get_transform().basis.x, deg2rad(y)).orthonormalized())
if pitch.get_transform().basis.get_euler().x > -PI / 2 and y < 0:
pitch.set_transform( pitch.get_transform() \\
.rotated(pitch.get_transform().basis.x, deg2rad(y)).orthonormalized())
func fire_or_return(alt):
if (!hasGun):
returnGun(alt)
return
if not canThrow: return
hasGun = false
get_node(\"throwGun\").pitch_scale = Engine.time_scale
if level1PickedUpGun and not level1AnimationShown:
anim.set_param(\"can_toss\", true)
level1AnimationShown = true
yield(delay(1.3), \"timeout\")
anim.set_trigger(\"throw_gun\")
yield(delay(0.33), \"timeout\")
var projectile : RigidBody = gun_projectile.instance()
var pos = find_node(\"Gun\").global_transform
projectile.global_transform = Transform(
Basis( pos.basis.x.normalized(), pos.basis.y.normalized(), pos.basis.z.normalized()),
pos.origin)
get_node(\"/root/Game\").level_add(projectile)
var direction = (look.get_collision_point() - pos.origin).normalized()
projectile.apply_central_impulse(direction * gun_speed)
projectile.player = self
throwGun_sound.play()
find_node(\"Gun\").visible = false
shotGun = projectile
func returnGun(alt):
var isColliding = targetGun.is_colliding() and targetGun.get_collider().name == \"Gun Target Area\"
if (shotGun and isColliding):
if alt:
anim.set_trigger(\"pull_right\")
else:
anim.set_trigger(\"pull_left\")
shotGun.recall(alt);
func _process(delta):
var moveVector = Vector2(
sqr_strength(\"strafe_left\") - sqr_strength(\"strafe_right\"),
sqr_strength(\"move_forward\") - sqr_strength(\"move_backward\")
)
if count_down < 0:
count_down -= 1
if count_down == 0:
camera.visible = false
anim.set_dual(\"can_throw\", canThrow)
desiredMoveVector = moveVector#.normalized()
var controller_aim_y = sqr_strength(\"look_down\") - sqr_strength(\"look_up\");
var controller_aim_x = sqr_strength(\"look_right\") - sqr_strength(\"look_left\");
move_aim(controller_aim_x * joy_aim_sensitivity_x * delta, controller_aim_y * joy_aim_sensitivity_y * delta)
func sqr_strength(action):
var val = Input.get_action_strength(action)
return val * val
func _physics_process(delta):
canThrow = preventSpawning.get_overlapping_bodies().size() == 0
if (shotGun != null):
var isColliding = targetGun.is_colliding() and targetGun.get_collider().name == \"Gun Target Area\"
anim.set_dual(\"hovering_over\", isColliding)
if isColliding:
shotGun.glow()
else:
shotGun.unglow()
func _integrate_forces(state):
var localAccelVector = Vector3(desiredMoveVector.x, 0, desiredMoveVector.y) * accel_speed
var globalAccelVector = yaw.get_global_transform().basis.xform(localAccelVector);
if globalAccelVector.length_squared() > 0.1:
state.add_force(globalAccelVector, Vector3())
# Cap movement speed
var flat_motion = Vector2(state.linear_velocity.x, state.linear_velocity.z)
if (flat_motion.length_squared() > max_move_speed * max_move_speed):
flat_motion = flat_motion.normalized() * max_move_speed
state.linear_velocity = Vector3(flat_motion.x, state.linear_velocity.y, flat_motion.y)
# Stop when not pressing anything
if desiredMoveVector.length_squared() < 0.01:
state.linear_velocity = Vector3(flat_motion.x * stop_factor, state.linear_velocity.y, flat_motion.y * stop_factor)
if try_jump:
try_jump = false
var contactCount = state.get_contact_count()
var isOnGround = false
for i in range(0, contactCount):
var normal = state.get_contact_local_normal(i)
if normal.dot(Vector3.UP) > 0.8:
isOnGround = true
break
if isOnGround:
apply_central_impulse(Vector3.UP * jump_force)
func pickupGun():
shotGun = null
hasGun = true
find_node(\"Gun\").visible = true
anim.set_param(\"pick_up\", true)
yield(delay(0.54), \"timeout\")
anim.set_param(\"pick_up\", false)
if is_level_1 and not level1PickedUpGun:
level1PickedUpGun = true
get_node(\"/root/Game\").showBigText(\"TAKE HIM OUT\")
if not is_level_1 or level1AnimationShown:
anim.set_param(\"can_toss\", true)
func delay(seconds : float = 1, start : bool = true):
var timer = Timer.new()
add_child(timer)
timer.one_shot = true
timer.wait_time = seconds
if start:
timer.start()
return timer
func _on_bullet_entered():
get_node(\"/root/Game\").player_died()
func _on_Pick_Up_Gun_area_entered(area):
if area.monitoring:
area.get_parent().queue_free()
pickupGun()
"
[sub_resource type="CapsuleShape" id=3]
radius = 0.55387
height = 2.50823
[sub_resource type="BoxShape" id=4]
extents = Vector3( 4.10969, 1.75175, 0.276674 )
[sub_resource type="BoxShape" id=5]
extents = Vector3( 0.400685, 0.400041, 0.860694 )
[node name="Player" type="RigidBody"]
collision_layer = 4
mode = 2
physics_material_override = SubResource( 1 )
continuous_cd = true
contacts_reported = 10
contact_monitor = true
can_sleep = false
script = SubResource( 2 )
max_move_speed = 8.0
accel_speed = 40.0
mouse_sensitivity_x = 0.169
mouse_sensitivity_y = 0.169
joy_aim_sensitivity_x = 130.0
joy_aim_sensitivity_y = 110.0
gun_speed = 190.0
jump_force = 6.0
gun_projectile = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-008, 1, 0, -1, -4.37114e-008, 0, 0, 0 )
shape = SubResource( 3 )
[node name="Humanoid Reference" parent="." instance=ExtResource( 2 )]
transform = Transform( 0.589347, 0, 0, 0, 0.589657, 0, 0, 0, 0.589657, 0.0144887, -1.79667, 0 )
visible = false
[node name="Yaw" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.12, 0 )
[node name="Pitch" type="Spatial" parent="Yaw"]
editor/display_folded = true
[node name="Head" type="Spatial" parent="Yaw/Pitch"]
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 0, 0, 0 )
[node name="Camera" type="Camera" parent="Yaw/Pitch/Head"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.32473e-007, 0, 0 )
current = true
[node name="Look" type="RayCast" parent="Yaw/Pitch/Head"]
enabled = true
cast_to = Vector3( 0, 0, -999 )
[node name="Pick Up Gun" type="Area" parent="Yaw/Pitch/Head/Look"]
transform = Transform( -1, 0, 8.74228e-008, 0, 1, 0, -8.74228e-008, 0, -1, 0, -1.12, 0 )
collision_layer = 4
collision_mask = 4
[node name="CollisionShape" type="CollisionShape" parent="Yaw/Pitch/Head/Look/Pick Up Gun"]
shape = SubResource( 4 )
[node name="Target Gun" type="RayCast" parent="Yaw/Pitch/Head"]
enabled = true
cast_to = Vector3( 0, 0, -999 )
collision_mask = 3
collide_with_areas = true
[node name="Gun Spawn Position" type="Position3D" parent="Yaw/Pitch"]
transform = Transform( 1, 0, 7.10543e-015, 0, 1, 0, -7.10543e-015, 0, 1, -0.838549, -0.315495, 2.04427 )
[node name="Direction" type="RayCast" parent="Yaw/Pitch/Gun Spawn Position"]
[node name="Prevent Spawning" type="Area" parent="Yaw/Pitch/Gun Spawn Position"]
[node name="CollisionShape" type="CollisionShape" parent="Yaw/Pitch/Gun Spawn Position/Prevent Spawning"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.43692 )
shape = SubResource( 5 )
[node name="Player Hand" parent="Yaw/Pitch" instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.64, -0.39, 0.73 )
[node name="Crosshair" type="TextureRect" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -32.0
margin_top = -32.0
margin_right = 32.0
margin_bottom = 32.0
rect_scale = Vector2( 0.5, 0.5 )
rect_pivot_offset = Vector2( 32, 32 )
mouse_filter = 2
texture = ExtResource( 4 )
stretch_mode = 5
[node name="throwGun" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
[node name="Materials" parent="." instance=ExtResource( 6 )]
visible = true
[connection signal="area_entered" from="Yaw/Pitch/Head/Look/Pick Up Gun" to="." method="_on_Pick_Up_Gun_area_entered"]