-
Notifications
You must be signed in to change notification settings - Fork 10
/
UltimatePlatformerController.gd
676 lines (580 loc) · 21.8 KB
/
UltimatePlatformerController.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
extends CharacterBody2D
class_name PlatformerController2D
@export var README: String = "IMPORTANT: MAKE SURE TO ASSIGN 'left' 'right' 'jump' 'dash' 'up' 'down' 'roll' 'latch' 'twirl' 'run' in the project settings input map. Usage tips. 1. Hover over each toggle and variable to read what it does and to make sure nothing bugs. 2. Animations are very primitive. To make full use of your custom art, you may want to slightly change the code for the animations"
#INFO READEME
#IMPORTANT: MAKE SURE TO ASSIGN 'left' 'right' 'jump' 'dash' 'up' 'down' 'roll' 'latch' 'twirl' 'run' in the project settings input map. THIS IS REQUIRED
#Usage tips.
#1. Hover over each toggle and variable to read what it does and to make sure nothing bugs.
#2. Animations are very primitive. To make full use of your custom art, you may want to slightly change the code for the animations
@export_category("Necesary Child Nodes")
@export var PlayerSprite: AnimatedSprite2D
@export var PlayerCollider: CollisionShape2D
#INFO HORIZONTAL MOVEMENT
@export_category("L/R Movement")
##The max speed your player will move
@export_range(50, 500) var maxSpeed: float = 200.0
##How fast your player will reach max speed from rest (in seconds)
@export_range(0, 4) var timeToReachMaxSpeed: float = 0.2
##How fast your player will reach zero speed from max speed (in seconds)
@export_range(0, 4) var timeToReachZeroSpeed: float = 0.2
##If true, player will instantly move and switch directions. Overrides the "timeToReach" variables, setting them to 0.
@export var directionalSnap: bool = false
##If enabled, the default movement speed will by 1/2 of the maxSpeed and the player must hold a "run" button to accelerate to max speed. Assign "run" (case sensitive) in the project input settings.
@export var runningModifier: bool = false
#INFO JUMPING
@export_category("Jumping and Gravity")
##The peak height of your player's jump
@export_range(0, 20) var jumpHeight: float = 2.0
##How many jumps your character can do before needing to touch the ground again. Giving more than 1 jump disables jump buffering and coyote time.
@export_range(0, 4) var jumps: int = 1
##The strength at which your character will be pulled to the ground.
@export_range(0, 100) var gravityScale: float = 20.0
##The fastest your player can fall
@export_range(0, 1000) var terminalVelocity: float = 500.0
##Your player will move this amount faster when falling providing a less floaty jump curve.
@export_range(0.5, 3) var descendingGravityFactor: float = 1.3
##Enabling this toggle makes it so that when the player releases the jump key while still ascending, their vertical velocity will cut by the height cut, providing variable jump height.
@export var shortHopAkaVariableJumpHeight: bool = true
##How much the jump height is cut by.
@export_range(1, 10) var jumpVariable: float = 2
##How much extra time (in seconds) your player will be given to jump after falling off an edge. This is set to 0.2 seconds by default.
@export_range(0, 0.5) var coyoteTime: float = 0.2
##The window of time (in seconds) that your player can press the jump button before hitting the ground and still have their input registered as a jump. This is set to 0.2 seconds by default.
@export_range(0, 0.5) var jumpBuffering: float = 0.2
#INFO EXTRAS
@export_category("Wall Jumping")
##Allows your player to jump off of walls. Without a Wall Kick Angle, the player will be able to scale the wall.
@export var wallJump: bool = false
##How long the player's movement input will be ignored after wall jumping.
@export_range(0, 0.5) var inputPauseAfterWallJump: float = 0.1
##The angle at which your player will jump away from the wall. 0 is straight away from the wall, 90 is straight up. Does not account for gravity
@export_range(0, 90) var wallKickAngle: float = 60.0
##The player's gravity will be divided by this number when touch a wall and descending. Set to 1 by default meaning no change will be made to the gravity and there is effectively no wall sliding. THIS IS OVERRIDDED BY WALL LATCH.
@export_range(1, 20) var wallSliding: float = 1.0
##If enabled, the player's gravity will be set to 0 when touching a wall and descending. THIS WILL OVERRIDE WALLSLIDING.
@export var wallLatching: bool = false
##wall latching must be enabled for this to work. #If enabled, the player must hold down the "latch" key to wall latch. Assign "latch" in the project input settings. The player's input will be ignored when latching.
@export var wallLatchingModifer: bool = false
@export_category("Dashing")
##The type of dashes the player can do.
@export_enum("None", "Horizontal", "Vertical", "Four Way", "Eight Way") var dashType: int
##How many dashes your player can do before needing to hit the ground.
@export_range(0, 10) var dashes: int = 1
##If enabled, pressing the opposite direction of a dash, during a dash, will zero the player's velocity.
@export var dashCancel: bool = true
##How far the player will dash. One of the dashing toggles must be on for this to be used.
@export_range(1.5, 4) var dashLength: float = 2.5
@export_category("Corner Cutting/Jump Correct")
##If the player's head is blocked by a jump but only by a little, the player will be nudged in the right direction and their jump will execute as intended. NEEDS RAYCASTS TO BE ATTACHED TO THE PLAYER NODE. AND ASSIGNED TO MOUNTING RAYCAST. DISTANCE OF MOUNTING DETERMINED BY PLACEMENT OF RAYCAST.
@export var cornerCutting: bool = false
##How many pixels the player will be pushed (per frame) if corner cutting is needed to correct a jump.
@export_range(1, 5) var correctionAmount: float = 1.5
##Raycast used for corner cutting calculations. Place above and to the left of the players head point up. ALL ARE NEEDED FOR IT TO WORK.
@export var leftRaycast: RayCast2D
##Raycast used for corner cutting calculations. Place above of the players head point up. ALL ARE NEEDED FOR IT TO WORK.
@export var middleRaycast: RayCast2D
##Raycast used for corner cutting calculations. Place above and to the right of the players head point up. ALL ARE NEEDED FOR IT TO WORK.
@export var rightRaycast: RayCast2D
@export_category("Down Input")
##Holding down will crouch the player. Crouching script may need to be changed depending on how your player's size proportions are. It is built for 32x player's sprites.
@export var crouch: bool = false
##Holding down and pressing the input for "roll" will execute a roll if the player is grounded. Assign a "roll" input in project settings input.
@export var canRoll: bool
@export_range(1.25, 2) var rollLength: float = 2
##If enabled, the player will stop all horizontal movement midair, wait (groundPoundPause) seconds, and then slam down into the ground when down is pressed.
@export var groundPound: bool
##The amount of time the player will hover in the air before completing a ground pound (in seconds)
@export_range(0.05, 0.75) var groundPoundPause: float = 0.25
##If enabled, pressing up will end the ground pound early
@export var upToCancel: bool = false
@export_category("Animations (Check Box if has animation)")
##Animations must be named "run" all lowercase as the check box says
@export var run: bool
##Animations must be named "jump" all lowercase as the check box says
@export var jump: bool
##Animations must be named "idle" all lowercase as the check box says
@export var idle: bool
##Animations must be named "walk" all lowercase as the check box says
@export var walk: bool
##Animations must be named "slide" all lowercase as the check box says
@export var slide: bool
##Animations must be named "latch" all lowercase as the check box says
@export var latch: bool
##Animations must be named "falling" all lowercase as the check box says
@export var falling: bool
##Animations must be named "crouch_idle" all lowercase as the check box says
@export var crouch_idle: bool
##Animations must be named "crouch_walk" all lowercase as the check box says
@export var crouch_walk: bool
##Animations must be named "roll" all lowercase as the check box says
@export var roll: bool
#Variables determined by the developer set ones.
var appliedGravity: float
var maxSpeedLock: float
var appliedTerminalVelocity: float
var friction: float
var acceleration: float
var deceleration: float
var instantAccel: bool = false
var instantStop: bool = false
var jumpMagnitude: float = 500.0
var jumpCount: int
var jumpWasPressed: bool = false
var coyoteActive: bool = false
var dashMagnitude: float
var gravityActive: bool = true
var dashing: bool = false
var dashCount: int
var rolling: bool = false
var twoWayDashHorizontal
var twoWayDashVertical
var eightWayDash
var wasMovingR: bool
var wasPressingR: bool
var movementInputMonitoring: Vector2 = Vector2(true, true) #movementInputMonitoring.x addresses right direction while .y addresses left direction
var gdelta: float = 1
var dset = false
var colliderScaleLockY
var colliderPosLockY
var latched
var wasLatched
var crouching
var groundPounding
var anim
var col
var animScaleLock : Vector2
#Input Variables for the whole script
var upHold
var downHold
var leftHold
var leftTap
var leftRelease
var rightHold
var rightTap
var rightRelease
var jumpTap
var jumpRelease
var runHold
var latchHold
var dashTap
var rollTap
var downTap
var twirlTap
func _ready():
wasMovingR = true
anim = PlayerSprite
col = PlayerCollider
_updateData()
func _updateData():
acceleration = maxSpeed / timeToReachMaxSpeed
deceleration = -maxSpeed / timeToReachZeroSpeed
jumpMagnitude = (10.0 * jumpHeight) * gravityScale
jumpCount = jumps
dashMagnitude = maxSpeed * dashLength
dashCount = dashes
maxSpeedLock = maxSpeed
animScaleLock = abs(anim.scale)
colliderScaleLockY = col.scale.y
colliderPosLockY = col.position.y
if timeToReachMaxSpeed == 0:
instantAccel = true
timeToReachMaxSpeed = 1
elif timeToReachMaxSpeed < 0:
timeToReachMaxSpeed = abs(timeToReachMaxSpeed)
instantAccel = false
else:
instantAccel = false
if timeToReachZeroSpeed == 0:
instantStop = true
timeToReachZeroSpeed = 1
elif timeToReachMaxSpeed < 0:
timeToReachMaxSpeed = abs(timeToReachMaxSpeed)
instantStop = false
else:
instantStop = false
if jumps > 1:
jumpBuffering = 0
coyoteTime = 0
coyoteTime = abs(coyoteTime)
jumpBuffering = abs(jumpBuffering)
if directionalSnap:
instantAccel = true
instantStop = true
twoWayDashHorizontal = false
twoWayDashVertical = false
eightWayDash = false
if dashType == 0:
pass
if dashType == 1:
twoWayDashHorizontal = true
elif dashType == 2:
twoWayDashVertical = true
elif dashType == 3:
twoWayDashHorizontal = true
twoWayDashVertical = true
elif dashType == 4:
eightWayDash = true
func _process(_delta):
#INFO animations
#directions
if is_on_wall() and !is_on_floor() and latch and wallLatching and ((wallLatchingModifer and latchHold) or !wallLatchingModifer):
latched = true
else:
latched = false
wasLatched = true
_setLatch(0.2, false)
if rightHold and !latched:
anim.scale.x = animScaleLock.x
if leftHold and !latched:
anim.scale.x = animScaleLock.x * -1
#run
if run and idle and !dashing and !crouching and !walk:
if abs(velocity.x) > 0.1 and is_on_floor() and !is_on_wall():
anim.speed_scale = abs(velocity.x / 150)
anim.play("run")
elif abs(velocity.x) < 0.1 and is_on_floor():
anim.speed_scale = 1
anim.play("idle")
elif run and idle and walk and !dashing and !crouching:
if abs(velocity.x) > 0.1 and is_on_floor() and !is_on_wall():
anim.speed_scale = abs(velocity.x / 150)
if abs(velocity.x) < (maxSpeedLock):
anim.play("walk")
else:
anim.play("run")
elif abs(velocity.x) < 0.1 and is_on_floor():
anim.speed_scale = 1
anim.play("idle")
#jump
if velocity.y < 0 and jump and !dashing:
anim.speed_scale = 1
anim.play("jump")
if velocity.y > 40 and falling and !dashing and !crouching:
anim.speed_scale = 1
anim.play("falling")
if latch and slide:
#wall slide and latch
if latched and !wasLatched:
anim.speed_scale = 1
anim.play("latch")
if is_on_wall() and velocity.y > 0 and slide and anim.animation != "slide" and wallSliding != 1:
anim.speed_scale = 1
anim.play("slide")
#dash
if dashing:
anim.speed_scale = 1
anim.play("dash")
#crouch
if crouching and !rolling:
if abs(velocity.x) > 10:
anim.speed_scale = 1
anim.play("crouch_walk")
else:
anim.speed_scale = 1
anim.play("crouch_idle")
if rollTap and canRoll and roll:
anim.speed_scale = 1
anim.play("roll")
func _physics_process(delta):
if !dset:
gdelta = delta
dset = true
#INFO Input Detectio. Define your inputs from the project settings here.
leftHold = Input.is_action_pressed("left")
rightHold = Input.is_action_pressed("right")
upHold = Input.is_action_pressed("up")
downHold = Input.is_action_pressed("down")
leftTap = Input.is_action_just_pressed("left")
rightTap = Input.is_action_just_pressed("right")
leftRelease = Input.is_action_just_released("left")
rightRelease = Input.is_action_just_released("right")
jumpTap = Input.is_action_just_pressed("jump")
jumpRelease = Input.is_action_just_released("jump")
runHold = Input.is_action_pressed("run")
latchHold = Input.is_action_pressed("latch")
dashTap = Input.is_action_just_pressed("dash")
rollTap = Input.is_action_just_pressed("roll")
downTap = Input.is_action_just_pressed("down")
twirlTap = Input.is_action_just_pressed("twirl")
#INFO Left and Right Movement
if rightHold and leftHold and movementInputMonitoring:
if !instantStop:
_decelerate(delta, false)
else:
velocity.x = -0.1
elif rightHold and movementInputMonitoring.x:
if velocity.x > maxSpeed or instantAccel:
velocity.x = maxSpeed
else:
velocity.x += acceleration * delta
if velocity.x < 0:
if !instantStop:
_decelerate(delta, false)
else:
velocity.x = -0.1
elif leftHold and movementInputMonitoring.y:
if velocity.x < -maxSpeed or instantAccel:
velocity.x = -maxSpeed
else:
velocity.x -= acceleration * delta
if velocity.x > 0:
if !instantStop:
_decelerate(delta, false)
else:
velocity.x = 0.1
if velocity.x > 0:
wasMovingR = true
elif velocity.x < 0:
wasMovingR = false
if rightTap:
wasPressingR = true
if leftTap:
wasPressingR = false
if runningModifier and !runHold:
maxSpeed = maxSpeedLock / 2
elif is_on_floor():
maxSpeed = maxSpeedLock
if !(leftHold or rightHold):
if !instantStop:
_decelerate(delta, false)
else:
velocity.x = 0
#INFO Crouching
if crouch:
if downHold and is_on_floor():
crouching = true
elif !downHold and !rolling:
crouching = false
if !is_on_floor():
crouching = false
if crouching:
maxSpeed = maxSpeedLock / 2
col.scale.y = colliderScaleLockY / 2
col.position.y = colliderPosLockY + (8 * colliderScaleLockY)
elif !runningModifier or (runningModifier and runHold):
maxSpeed = maxSpeedLock
col.scale.y = colliderScaleLockY
col.position.y = colliderPosLockY
#INFO Rolling
if canRoll and is_on_floor() and rollTap and crouching:
_rollingTime(rollLength * 0.25)
if wasPressingR and !(upHold):
velocity.y = 0
velocity.x = maxSpeedLock * rollLength
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(rollLength * 0.0625)
elif !(upHold):
velocity.y = 0
velocity.x = -maxSpeedLock * rollLength
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(rollLength * 0.0625)
if canRoll and rolling:
#if you want your player to become immune or do something else while rolling, add that here.
pass
#INFO Jump and Gravity
if velocity.y > 0:
appliedGravity = gravityScale * descendingGravityFactor
else:
appliedGravity = gravityScale
if is_on_wall() and !groundPounding:
appliedTerminalVelocity = terminalVelocity / wallSliding
if wallLatching and ((wallLatchingModifer and latchHold) or !wallLatchingModifer):
appliedGravity = 0
if velocity.y < 0:
velocity.y += 50
if velocity.y > 0:
velocity.y = 0
if wallLatchingModifer and latchHold and movementInputMonitoring == Vector2(true, true):
velocity.x = 0
elif wallSliding != 1 and velocity.y > 0:
appliedGravity = appliedGravity / wallSliding
elif !is_on_wall() and !groundPounding:
appliedTerminalVelocity = terminalVelocity
if gravityActive:
if velocity.y < appliedTerminalVelocity:
velocity.y += appliedGravity
elif velocity.y > appliedTerminalVelocity:
velocity.y = appliedTerminalVelocity
if shortHopAkaVariableJumpHeight and jumpRelease and velocity.y < 0:
velocity.y = velocity.y / jumpVariable
if jumps == 1:
if !is_on_floor() and !is_on_wall():
if coyoteTime > 0:
coyoteActive = true
_coyoteTime()
if jumpTap and !is_on_wall():
if coyoteActive:
coyoteActive = false
_jump()
if jumpBuffering > 0:
jumpWasPressed = true
_bufferJump()
elif jumpBuffering == 0 and coyoteTime == 0 and is_on_floor():
_jump()
elif jumpTap and is_on_wall() and !is_on_floor():
if wallJump and !latched:
_wallJump()
elif wallJump and latched:
_wallJump()
elif jumpTap and is_on_floor():
_jump()
if is_on_floor():
jumpCount = jumps
if coyoteTime > 0:
coyoteActive = true
else:
coyoteActive = false
if jumpWasPressed:
_jump()
elif jumps > 1:
if is_on_floor():
jumpCount = jumps
if jumpTap and is_on_wall() and wallJump:
_wallJump()
elif jumpTap and jumpCount > 0:
velocity.y = -jumpMagnitude
jumpCount = jumpCount - 1
_endGroundPound()
#INFO dashing
if is_on_floor():
dashCount = dashes
if eightWayDash and dashTap and dashCount > 0 and !rolling:
var input_direction = Input.get_vector("left", "right", "up", "down")
var dTime = 0.0625 * dashLength
_dashingTime(dTime)
_pauseGravity(dTime)
velocity = dashMagnitude * input_direction
if (!rightHold and !leftHold and !downHold and !upHold) and wasMovingR:
velocity.x = dashMagnitude
elif (!rightHold and !leftHold and !downHold and !upHold) and !wasMovingR:
velocity.x = -dashMagnitude
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(dTime)
if twoWayDashVertical and dashTap and dashCount > 0 and !rolling:
var dTime = 0.0625 * dashLength
if upHold and downHold:
_placeHolder()
elif upHold:
_dashingTime(dTime)
_pauseGravity(dTime)
velocity.x = 0
velocity.y = -dashMagnitude
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(dTime)
elif downHold and dashCount > 0:
_dashingTime(dTime)
_pauseGravity(dTime)
velocity.x = 0
velocity.y = dashMagnitude
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(dTime)
if twoWayDashHorizontal and dashTap and dashCount > 0 and !rolling:
var dTime = 0.0625 * dashLength
if wasPressingR and !(upHold or downHold):
velocity.y = 0
velocity.x = dashMagnitude
_pauseGravity(dTime)
_dashingTime(dTime)
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(dTime)
elif !(upHold or downHold):
velocity.y = 0
velocity.x = -dashMagnitude
_pauseGravity(dTime)
_dashingTime(dTime)
dashCount += -1
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(dTime)
if dashing and velocity.x > 0 and leftTap and dashCancel:
velocity.x = 0
if dashing and velocity.x < 0 and rightTap and dashCancel:
velocity.x = 0
#INFO Corner Cutting
if cornerCutting:
if velocity.y < 0 and leftRaycast.is_colliding() and !rightRaycast.is_colliding() and !middleRaycast.is_colliding():
position.x += correctionAmount
if velocity.y < 0 and !leftRaycast.is_colliding() and rightRaycast.is_colliding() and !middleRaycast.is_colliding():
position.x -= correctionAmount
#INFO Ground Pound
if groundPound and downTap and !is_on_floor() and !is_on_wall():
groundPounding = true
gravityActive = false
velocity.y = 0
await get_tree().create_timer(groundPoundPause).timeout
_groundPound()
if is_on_floor() and groundPounding:
_endGroundPound()
move_and_slide()
if upToCancel and upHold and groundPound:
_endGroundPound()
func _bufferJump():
await get_tree().create_timer(jumpBuffering).timeout
jumpWasPressed = false
func _coyoteTime():
await get_tree().create_timer(coyoteTime).timeout
coyoteActive = false
jumpCount += -1
func _jump():
if jumpCount > 0:
velocity.y = -jumpMagnitude
jumpCount += -1
jumpWasPressed = false
func _wallJump():
var horizontalWallKick = abs(jumpMagnitude * cos(wallKickAngle * (PI / 180)))
var verticalWallKick = abs(jumpMagnitude * sin(wallKickAngle * (PI / 180)))
velocity.y = -verticalWallKick
var dir = 1
if wallLatchingModifer and latchHold:
dir = -1
if wasMovingR:
velocity.x = -horizontalWallKick * dir
else:
velocity.x = horizontalWallKick * dir
if inputPauseAfterWallJump != 0:
movementInputMonitoring = Vector2(false, false)
_inputPauseReset(inputPauseAfterWallJump)
func _setLatch(delay, setBool):
await get_tree().create_timer(delay).timeout
wasLatched = setBool
func _inputPauseReset(time):
await get_tree().create_timer(time).timeout
movementInputMonitoring = Vector2(true, true)
func _decelerate(delta, vertical):
if !vertical:
if (abs(velocity.x) > 0) and (abs(velocity.x) <= abs(deceleration * delta)):
velocity.x = 0
elif velocity.x > 0:
velocity.x += deceleration * delta
elif velocity.x < 0:
velocity.x -= deceleration * delta
elif vertical and velocity.y > 0:
velocity.y += deceleration * delta
func _pauseGravity(time):
gravityActive = false
await get_tree().create_timer(time).timeout
gravityActive = true
func _dashingTime(time):
dashing = true
await get_tree().create_timer(time).timeout
dashing = false
if !is_on_floor():
velocity.y = -gravityScale * 10
func _rollingTime(time):
rolling = true
await get_tree().create_timer(time).timeout
rolling = false
func _groundPound():
appliedTerminalVelocity = terminalVelocity * 10
velocity.y = jumpMagnitude * 2
func _endGroundPound():
groundPounding = false
appliedTerminalVelocity = terminalVelocity
gravityActive = true
func _placeHolder():
print("")