-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFallingPlayer.js
904 lines (708 loc) · 29.1 KB
/
FallingPlayer.js
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
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
#pragma strict
private var fallingLaunch : GameObject;
private var fallingLaunchComponent : FallingLaunch;
// 10/25/2017: `Color` uses a 0-1 float range, not 0-2, in Unity.
// 2 = 255 for rgba in this color array
// static var startingFogColor : Color = Color(1.17, 1.17, 1.17, 2);
static var startingFogEndDistance : int = 1500;
static var startingFogStartDistance : int = 150;
static var startingCloudsAlpha : float = .25f; // Unity 4 used .39f (99 in RGBA)
//original for corroded sky tubes level
//static var startingFogEndDistance : int = 2500;
//static var startingCameraFarClipPlane : int = 2700;
var changeBackdrop : changeBackdrop;
changeBackdrop = GetComponent("changeBackdrop");
var levelChangeBackdrop : boolean = false;
var ScoreFlashTexture : GameObject;
static var ScoreFlashTextureScript : GUITextureLaunch;
ScoreFlashTextureScript = ScoreFlashTexture.GetComponent("GUITextureLaunch");
var lifeCountdownScript : lifeCountdown;
public var force:float = 1.0;
var dir : Vector3 = Vector3.zero;
enum FadeDir {In, Out}
var fadeTime : float = 0.75;
var origMat : Material;
//var thisOceanCamera : Component;
// Move object using accelerometer
var speed = 5.0;
var target : Transform;
var smooth = 2.0;
var tiltAngle = 30.0;
var tiltAroundZ : float;
var tiltAroundX : float;
//var flipMultiplier : int = 1;
//var flipMultiplier = FallingLaunch.flipMultiplier;
var script : ScoreController;
script = GetComponent("ScoreController");
private var homeLevel : String = "Falling-scene-menu";
static var isAlive : int = 1;
static var lifeStartTime : float = 0;
static var levelStartTime : float = 0;
static var isTiltable : boolean = true;
static var isPausable : boolean = false;
private var isExitableFromVR : boolean = true;
var isExitingLevel : boolean = false;
var UIscriptName : GameObject;
static var UIscriptComponent : fallingUITest;
var deathFadeUIVR : GameObject;
private var deathFadeUIVRRenderer : Renderer;
private var deathFadeUIVRMatl : Material;
var opaqueDeathFadeUIVR : GameObject;
private var opaqueDeathFadeUIVRRenderer : Renderer;
private var opaqueDeathFadeUIVRMatl : Material;
var levelStartUIVR : GameObject;
var deathPauseUIVR : GameObject;
var whiteFadeUIVR : GameObject;
private var whiteFadeUIVRRenderer : Renderer;
private var whiteFadeUIVRMatl : Material;
var whiteFadeEndGameUIVR : GameObject;
private var whiteFadeEndGameUIVRRenderer : Renderer;
private var whiteFadeEndGameUIVRMatl : Material;
var scoreUIVR : GameObject;
private var scoreUIVRRenderer : Renderer;
private var scoreUIVRMatl : Material;
private var peakScoreFlashValueVR : float = 1.0;
var reticleVRUIObj : GameObject;
static var reticleVRUIScript : VRLifeMeter;
var endGameUIObjVR : GameObject;
private var endGameUIVRRenderer : Renderer;
private var endGameUIVRMatl : Material;
var clearDestroyedObjects : boolean = false;
var whiteFader : FadeInOutAlt;
private var introComponent : IntroSequence1stPerson;
introComponent = GetComponent("IntroSequence1stPerson");
var simpleVelocityLimiterComponent : SimpleVelocityLimiter;
simpleVelocityLimiterComponent = GetComponent("SimpleVelocityLimiter");
var playAltScoreAudio : boolean = false;
var clipToPlay : float;
var audioToPlay : AudioSource;
var pitchRand : float;
var audioScore : AudioSource;
var audioScoreAlt : AudioSource;
var audioDeath : AudioSource;
var audioLevelEnd : AudioSource;
var myVol : float;
var peakVol : float;
private var myTransform : Transform;
private var myMainCamera : Camera;
private var myMainCameraTransform : Transform;
private var myBackdrop : GameObject;
private var myBackdropRenderer : Renderer;
private var BackdropMist : GameObject;
private var myVRViewer : GameObject;
private var holdTime : float = 1.5; // continuous hold time needed to trigger a return-to-menu
private var holdAccumTime : float = 0.0;
private var holdThresholdForShowingLoadingBar : float = 0.5;
private var touchHoldStartTime : float = 0.0;
private var isTouchingResetUI : boolean = false;
var rb : Rigidbody;
function Awake() {
// if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight) {
// flipMultiplier = -1;
//}
myTransform = transform;
}
function Start() {
fallingLaunch = GameObject.Find("LaunchGameObject");
fallingLaunchComponent = fallingLaunch.GetComponent.<FallingLaunch>();
if (!FallingLaunch.isVRMode) {
// In case the calculation in the start menu was wrong/outmoded:
fallingLaunchComponent.LockDeviceOrientation(1.0);
}
myMainCamera = Camera.main;
// Go up one level; this is the Player-cameras container object, which will get rotated on tilt:
myMainCameraTransform = myMainCamera.gameObject.transform.parent;
myBackdrop = GameObject.Find("plane-close");
BackdropMist = GameObject.Find("Cylinder");
myBackdropRenderer = myBackdrop ? myBackdrop.GetComponent.<Renderer>() : null;
lifeCountdownScript = gameObject.GetComponent.<lifeCountdown>();
if (FallingLaunch.isVRMode) {
myVRViewer = GameObject.Find("GvrViewerMain");
scoreUIVRRenderer = scoreUIVR.GetComponent.<Renderer>();
scoreUIVRMatl = scoreUIVRRenderer.material;
scoreUIVRMatl.color.a = 0;
whiteFadeUIVRRenderer = whiteFadeUIVR.GetComponent.<Renderer>();
whiteFadeUIVRMatl = whiteFadeUIVRRenderer.material;
whiteFadeUIVRMatl.color.a = 0;
if (whiteFadeEndGameUIVR) {
whiteFadeEndGameUIVRRenderer = whiteFadeEndGameUIVR.GetComponent.<Renderer>();
whiteFadeEndGameUIVRMatl = whiteFadeEndGameUIVRRenderer.material;
whiteFadeEndGameUIVRMatl.color.a = 0;
}
// Hack to have two separate death/fade-to-black sphere objects,
// but neither shader does everything. The inverted transparent shader occludes
// all physical objects, but the UIToolkit one is needed for covering light halos.
// The opaque and transparent materials have manual RenderQueue settings
// of 5000 (the official max) and 6000, respectively.
if (deathFadeUIVR && opaqueDeathFadeUIVR) {
deathFadeUIVRRenderer = deathFadeUIVR.GetComponent.<Renderer>();
deathFadeUIVRMatl = deathFadeUIVRRenderer.material;
opaqueDeathFadeUIVRRenderer = opaqueDeathFadeUIVR.GetComponent.<Renderer>();
opaqueDeathFadeUIVRMatl = opaqueDeathFadeUIVRRenderer.material;
if (deathFadeUIVRMatl.HasProperty("_Color")) {
deathFadeUIVRMatl.color.a = 0;
}
if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) {
var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor");
currentColor.a = 0;
opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor);
}
}
if (reticleVRUIObj) {
reticleVRUIScript = reticleVRUIObj.GetComponent.<VRLifeMeter>();
} else {
Debug.LogError("You forgot to assign an object for the VR reticle... trying to look up manually");
reticleVRUIScript = GameObject.Find("vr-radial-life-meter").GetComponent.<VRLifeMeter>();
}
}
startingFogEndDistance = RenderSettings.fogEndDistance;
startingFogStartDistance = RenderSettings.fogStartDistance;
isAlive = 1;
UIscriptComponent = UIscriptName.GetComponent(fallingUITest);
lifeStartTime = Time.time;
levelStartTime = Time.time;
isExitingLevel = false;
FallingLaunch.thisLevel = Application.loadedLevelName;
FallingLaunch.thisLevelArea = "0-start";
AudioListener.pause = false;
myVol = audioScore.volume;
peakVol = audioScore.volume;
FadeAudio(0.1, FadeDir.In);
isPausable = false;
rb = GetComponent.<Rigidbody>();
if (FallingLaunch.isVRMode && levelStartUIVR && FallingLaunch.shouldShowVRIntroUI) {
levelStartUIVR.SetActive(true);
isAlive = 0;
rb.isKinematic = true;
} else {
isAlive = 1;
rb.isKinematic = false;
}
// introComponent's existence is a proxy for level 1,
// where we don't want the reticle to be visible yet
// (resuming from a level 1 post-intro checkpoint
// is handled in Respawn.js (mainRespawnScript):
if (!introComponent) {
UIscriptComponent.UnhideGUI();
if (FallingLaunch.isVRMode) {
reticleVRUIScript.FadeReticleIn(1.5);
}
}
LevelStartFade();
}
function LevelStartFade () {
if (PlayerPrefs.HasKey("LatestLevel") &&
PlayerPrefs.GetString("LatestLevel") == Application.loadedLevelName) {
FallingLaunch.LoadedLatestLevel = true;
}
if (FallingLaunch.LoadedLatestLevel == false) {
introFade();
}
}
function introFade() {
// this disables (unchecks) the script FadeInOutAlt after three seconds,
// so OnGui is only called at the start of each level load.
yield WaitForSeconds (3);
whiteFader = Camera.main.GetComponent(FadeInOutAlt);
whiteFader.enabled = false;
}
function introNow() {
LatestCheckpointRespawn();
yield WaitForSeconds (3);
FallingLaunch.LoadedLatestLevel = false;
whiteFader = Camera.main.GetComponent(FadeInOutAlt);
if (whiteFader) {whiteFader.enabled = false;}
}
function FadeAudio(timer : float, fadeType : FadeDir) {
var start = fadeType == FadeDir.In? 0.0 : 1.0;
var end = fadeType == FadeDir.In? 1.0 : 0.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
// var t : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp
AudioListener.volume = Mathf.Lerp(start, end, i);
yield;
}
}
function ShowDeathInterstitialVR() {
rb.isKinematic = true;
isAlive = 0;
deathPauseUIVR.SetActive(true);
yield DeathFadeVR(1.0, FadeDir.In);
// yield UIscriptComponent.fadeIn(false);
// Managing isExitableFromVR gives finer control over the exit UI,
// preventing the player from tapping mid-respawn fadeout.
isExitableFromVR = true;
// yield WaitForSeconds(4);
while (true && FallingLaunch.isVRMode && isAlive == 0 && Input.touchCount == 0 &&
deathPauseUIVR.activeInHierarchy && isExitableFromVR && !isTouchingResetUI) {
yield WaitForSeconds(4);
if (isAlive == 0 && Input.touchCount == 0 && deathPauseUIVR.activeInHierarchy &&
isExitableFromVR && !isTouchingResetUI) {
// Debug.Log("it's been enough time; auto-respawning");
RespawnAfterDeathInterstitialVR();
}
}
// // Only execute this if it's been four seconds and a respawn is not already underway:
// if (isAlive == 0 && deathPauseUIVR.activeInHierarchy && isExitableFromVR) {
// RespawnAfterDeathInterstitialVR();
// }
}
function RespawnAfterDeathInterstitialVR() {
isExitableFromVR = false;
yield DeathFadeVR(0.5, FadeDir.Out);
rb.isKinematic = false;
// TODO: Fade out material here instead of toggling the whole object outright?
deathPauseUIVR.SetActive(false);
// resetting score to max here for VR, to avoid the score
// ticking away over the preceding ~4 WaitForSeconds.
script.ResetScore();
// In VR mode, we ignore fadeTime in favor of a longer fade-in
// matched to the longer waiting interval below:
FadeAudio(2.0, FadeDir.In);
DeathFadeVR(1.0, FadeDir.In);
isPausable = true;
// setting isAlive is order-dependent with lerpControlIn below
// (isAlive = 0 will break its loop):
isAlive = 1;
lerpControlIn(3.0);
yield WaitForSeconds(1);
reticleVRUIScript.FadeReticleIn(1.5);
}
function DeathRespawn () {
isPausable = false;
rb.isKinematic = true;
lifeStartTime = Time.time;
var respawnPosition = Respawn.currentRespawn.transform.position;
if (FallingLaunch.isVRMode) {
reticleVRUIScript.FadeReticleOut(0.5);
FadeAudio(1.5, FadeDir.Out);
yield DeathFadeVR(1.0, FadeDir.Out);
} else {
FadeAudio(fadeTime, FadeDir.Out);
yield UIscriptComponent.fadeOut();
}
if (levelChangeBackdrop == true) {
changeLevelBackdrop ();
}
// VR mode does its own score reset later, due to a longer fade interval/
// interstitial 'back to menu' screen.
if (!FallingLaunch.isVRMode) {
script.ResetScore();
}
// If you want to clear destroyed projectiles (set per-level)...
if (clearDestroyedObjects) {
Resources.UnloadUnusedAssets();
}
isAlive = 1;
RenderSettings.fogEndDistance = startingFogEndDistance;
RenderSettings.fogStartDistance = startingFogStartDistance;
// Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too
GetComponent.<Collider>().attachedRigidbody.transform.Translate(respawnPosition);
// Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
myTransform.position = respawnPosition; // + Vector3.up;
rb.isKinematic = false;
MoveController.controlMultiplier = 1.0;
if (FallingLaunch.isVRMode && deathPauseUIVR && deathFadeUIVR) {
ShowDeathInterstitialVR();
} else {
FadeAudio(fadeTime, FadeDir.In);
lerpControlIn(3.0);
yield UIscriptComponent.fadeIn(true);
}
}
function LatestCheckpointRespawn () {
isPausable = false;
rb.isKinematic = true;
var respawnPosition = Respawn.currentRespawn.transform.position;
//UIscriptComponent.fadeOut();
if (levelChangeBackdrop == true) {
changeLevelBackdrop ();
}
// yield WaitForSeconds(1);
// if in VR intro, don't set isAlive yet, since that will start the lifeCountdown timer ticking:
if (FallingLaunch.isVRMode && FallingLaunch.shouldShowVRIntroUI) {
isAlive = 0;
} else {
isAlive = 1;
}
RenderSettings.fogEndDistance = startingFogEndDistance;
RenderSettings.fogStartDistance = startingFogStartDistance;
GetComponent.<Collider>().attachedRigidbody.transform.Translate(respawnPosition);
myTransform.position = respawnPosition; // + Vector3.up;
FadeAudio(fadeTime, FadeDir.In);
if (!FallingLaunch.isVRMode) {
rb.isKinematic = false;
lerpControlIn(3.0);
UIscriptComponent.UnhideGUI();
}
}
function ShowDeathHelp() {
if (introComponent) {
introComponent.DeathHelp();
}
}
function changeLevelBackdrop () {
if (!FallingLaunch.isVRMode) {
if (changeBackdrop.oceanCameraVR) {
changeBackdrop.oceanCameraVR.GetComponent(Camera).enabled = false;
}
}
// needed even in VR mode, so the ocean renderer disables on respawn:
if (changeBackdrop.oceanCamera) {
changeBackdrop.oceanCamera.GetComponent(Camera).enabled = false;
changeBackdrop.oceanRenderer.enabled = false;
}
// the Fade argument below this breaks unpredictably if player gameobject lacks a Fade script component
// Fade.use.Colors(guiTexture, (RenderSettings.fogColor * 2), startingFogColor, 2.0);
RenderSettings.fogEndDistance = startingFogEndDistance;
RenderSettings.fogStartDistance = startingFogStartDistance;
if (myMainCamera) {
// reset regular or VR cameras' clip planes (handles both cases internally):
changeBackdrop.ResetCameraClipPlane();
}
if (myBackdropRenderer) {
myBackdropRenderer.materials = [origMat];
}
if (BackdropMist) {
iTween.ColorTo(BackdropMist,{"a": startingCloudsAlpha,"time": .5});
}
}
function Update () {
// playerTilt moves camera on device tilt. Enable if not in VR mode:
if (!FallingLaunch.isVRMode) {
playerTilt();
}
// disable VR mode and return to menu on screen touch while dead:
if (FallingLaunch.isVRMode) {
if (FallingLaunch.showingVREndGameUI) {
for (var i3 = 0; i3 < Input.touchCount; ++i3) {
if (Input.GetTouch(i3).phase == TouchPhase.Ended && Input.GetTouch(i3).phase != TouchPhase.Canceled) {
// PlayerPrefs.DeleteKey("LatestCheckpoint");
// PlayerPrefs.SetString("LatestLevel", "Falling-scene-tutorial");
FallingLaunch.showingVREndGameUI = false;
Application.LoadLevel(homeLevel);
}
}
}
if (isAlive == 0 && deathPauseUIVR.activeInHierarchy) { //} && isExitableFromVR) {
if (Input.touchCount > 0) {
// Debug.Log("Starting touchHoldStartTime " + touchHoldStartTime);
// Debug.Log("Time.time " + Time.time);
// as soon as any fingers are on screen, block the auto-respawning:
isExitableFromVR = false;
if (Input.GetTouch(0).phase == TouchPhase.Began) {
touchHoldStartTime = Time.time;
isTouchingResetUI = true;
}
// var adjustedHoldAccumTime : float = (touchHoldStartTime < Time.time) ? 0.0 :
var adjustedHoldAccumTime : float = !isTouchingResetUI ? 0.0 :
Mathf.Max(Time.time - touchHoldStartTime - holdThresholdForShowingLoadingBar, 0.0);
// holdAccumTime += Input.GetTouch(0).deltaTime;
// Old way, using accumulated touch time instead of subtractive via Time.time:
// var adjustedHoldAccumTime : float = (touchHoldStartTime < Time.time) ? 0.0 :
// Mathf.Max(holdAccumTime - holdThresholdForShowingLoadingBar, 0.0);
if (adjustedHoldAccumTime > 0.0) {
// Debug.Log("Updating loading circle with adjustedHoldAccumTime " + adjustedHoldAccumTime);
// takes care of showing and updating filled 'loading' sprite:
reticleVRUIScript.UpdateLoadingCircle(
adjustedHoldAccumTime / holdTime
);
}
// Long tap (~2+ secs):
if (adjustedHoldAccumTime >= holdTime) {
// Debug.Log("long tap with adjustedHoldAccumTime " + adjustedHoldAccumTime);
reticleVRUIScript.HideLoadingCircle();
isPausable = false;
fallingLaunchComponent.DisableVRMode();
UIscriptComponent.SaveCheckpointVR();
Application.LoadLevel(homeLevel);
}
if (Input.GetTouch(0).phase == TouchPhase.Ended) {
reticleVRUIScript.HideLoadingCircle();
var actualTouchTime : float = !isTouchingResetUI ? 0.0 : Time.time - touchHoldStartTime;
// Short-ish tap (in practice, under ~.875 seconds):
if (actualTouchTime > 0.0 && adjustedHoldAccumTime <= holdTime / 4.0) {
// Debug.Log(
// "With adjustedHoldAccumTime " + adjustedHoldAccumTime +
// ", that counts as a short tap; time to respawn!"
// );
// Debug.Log(
// "With actualTouchTime " + actualTouchTime +
// ", that counts as a short tap; time to respawn!"
// );
RespawnAfterDeathInterstitialVR();
}
holdAccumTime = 0;
}
} else {
// holdAccumTime = 0;
isTouchingResetUI = false;
// Once no fingers are touching, resetting this boolean will let the loop
// in ShowDeathInterstitialVR respawn the player after a 4-second delay.
isExitableFromVR = true;
}
} else {
isTouchingResetUI = false;
}
if (levelStartUIVR.activeInHierarchy && FallingLaunch.shouldShowVRIntroUI) {
for (var i2 = 0; i2 < Input.touchCount; ++i2) {
if (Input.GetTouch(i2).phase == TouchPhase.Ended && Input.GetTouch(i2).phase != TouchPhase.Canceled) {
ContinueFromLevelStartVR();
}
}
}
}
//Debug.Log("slowdown is: " + MoveController.Slowdown + " and myVol is: " + myVol);
//Debug.Log("your current acceleration is: " + FallingLaunch.accelerator);
}
function playerTilt() {
if (isTiltable == true) {
var dir : Vector3 = Vector3.zero;
if (FallingLaunch.hasSetAccel == false) {
FallingLaunch.accelerator = FallingLaunch.calibrationRotation * Input.acceleration;
}
tiltAroundX = FallingLaunch.invertVertAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.x * tiltAngle)), -tiltAngle, tiltAngle);
tiltAroundZ = FallingLaunch.invertHorizAxisVal * Mathf.Clamp((FallingLaunch.flipMultiplier * (-FallingLaunch.accelerator.y * tiltAngle)), -tiltAngle, tiltAngle);
var target : Quaternion = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
// Dampen towards the target rotation
// Rotating the camera transform, not the Player transform itself, so the 3D clouds
// (which are the child of the Player object) have correct tilt context.
myMainCameraTransform.rotation = Quaternion.Lerp(myMainCameraTransform.rotation, target,
Time.deltaTime * smooth);
}
}
function lerpControlIn(timer : float) {
// Debug.Log("your flip multiplier is " + FallingLaunch.flipMultiplier);
// Debug.Log("your control multiplier is " + MoveController.controlMultiplier);
var start = 0.0;
var end = 1.0; // MoveController.controlMultiplier;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
MoveController.controlMultiplier = Mathf.Lerp(start, end, i);
if (isAlive == 0) {MoveController.controlMultiplier = end; break;}
yield;
if (i >= 1.0 || isAlive == 0) {MoveController.controlMultiplier = end; break;}
}
yield WaitForSeconds (timer);
}
function lerpControlOut(timer : float) {
var startControl : float = MoveController.controlMultiplier;
var end : float = 0.0;
var startMaxVelocity : float = simpleVelocityLimiterComponent.GetMaxVelocity();
var endVelocity : float = 0; // startMaxVelocity * .15; // / 3;
// timer 1 and 2 run sequentially via the two `yields` /
// inner `while` looops below, adding up to the overall `timer` argument:
var timer2 : float = 1.25;
var timer1 : float = timer - timer2;
var i = 0.0;
var step = 1.0/timer1;
while (i <= 1.0) {
i += step * Time.deltaTime;
var controlT : float = Mathf.Sin(i * Mathf.PI * 0.5f); // ease-out lerp
MoveController.controlMultiplier = Mathf.Lerp(startControl, end, controlT);
if (isAlive == 0) {
MoveController.controlMultiplier = startControl;
simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity);
break;
}
yield;
// the && is because the smootherstep math can overshoot 1.0 on its own:
if (i >= 1.0 && isAlive == 0) {
MoveController.controlMultiplier = startControl;
simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity);
break;
}
}
// In the final bit of time (timer2), lerp the speed cap down to zero:
var i2 : float = 0.0;
var step2 = 1.0/timer2;
while (i2 <= 1.0) {
i2 += step2 * Time.deltaTime;
// var maxVelocityT : float = i2*i2*i2 * (i2 * (6f*i2 - 15f) + 10f); // smootherstep lerp
var maxVelocityT : float = Mathf.Sin(i2 * Mathf.PI * 0.5f); // ease-out lerp
var newMaxVelocity : float = Mathf.Lerp(startMaxVelocity, endVelocity, maxVelocityT);
simpleVelocityLimiterComponent.SetMaxVelocity(newMaxVelocity);
if (isAlive == 0) {
MoveController.controlMultiplier = startControl;
simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity);
break;
}
yield;
// the && is because the smootherstep math can overshoot 1.0 on its own:
if (i2 >= 1.0 && isAlive == 0) {
MoveController.controlMultiplier = startControl;
simpleVelocityLimiterComponent.SetMaxVelocity(startMaxVelocity);
break;
}
}
}
function ScoreFlashVR (timer : float, fadeType : FadeDir) {
var start = fadeType == FadeDir.In? 0.0 : peakScoreFlashValueVR;
var end = fadeType == FadeDir.In? peakScoreFlashValueVR : 0.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
scoreUIVRMatl.color.a = Mathf.Lerp(start, end, i);
yield;
}
}
function DeathFadeVR (timer : float, fadeType : FadeDir) {
var start = fadeType == FadeDir.In ? 1.0 : 0.0;
var end = fadeType == FadeDir.In ? 0.0 : 1.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
// ease-out lerp, to match non-VR fade timing:
var t : float = Mathf.Sin(i * Mathf.PI * 0.5f);
if (deathFadeUIVRMatl.HasProperty("_Color")) {
deathFadeUIVRMatl.color.a = Mathf.Lerp(start, end, t);
}
if (opaqueDeathFadeUIVRMatl.HasProperty("_TintColor")) {
var currentColor : Color = opaqueDeathFadeUIVRMatl.GetColor("_TintColor");
currentColor.a = Mathf.Lerp(start, end, t);
opaqueDeathFadeUIVRMatl.SetColor("_TintColor", currentColor);
}
yield;
}
}
function WhiteFadeVR (timer : float, fadeType : FadeDir) {
var start = fadeType == FadeDir.In ? 1.0 : 0.0;
var end = fadeType == FadeDir.In ? 0.0 : 1.0;
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
whiteFadeUIVRMatl.color.a = Mathf.Lerp(start, end, i);
yield;
}
}
function WhiteFadeVREndGame (timer : float) {
var start = 0.0;
var end = 0.66;
var i = 0.0;
var step = 1.0/timer;
if (endGameUIObjVR) {
endGameUIObjVR.SetActive(true);
endGameUIVRRenderer = endGameUIObjVR.GetComponent.<Renderer>();
endGameUIVRMatl = endGameUIVRRenderer.material;
}
if (whiteFadeEndGameUIVR) {
whiteFadeEndGameUIVR.SetActive(true);
}
while (i <= 1.0) {
i += step * Time.deltaTime;
whiteFadeEndGameUIVRMatl.color.a = Mathf.Lerp(start, end, i);
if (endGameUIVRMatl) {endGameUIVRMatl.color.a = Mathf.Lerp(start, end, i);}
yield;
}
// this will allow screen taps to return to the main menu:
FallingLaunch.showingVREndGameUI = true;
}
function OnCollisionEnter (collision : Collision) {
// Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x);
// Screen.sleepTimeout = 0.0f;
if (collision.gameObject.CompareTag ("Death") && isAlive == 1) {
if (isPausable == true || collision.gameObject.layer == 17 ) {
isAlive = 0;
isPausable = false;
if (!FallingLaunch.isVRMode) {
lifeCountdown.LifeFlashTextureScript.FadeFlash(1, FadeDir.Out);
UIscriptComponent.HideGUI();
} else {
lifeCountdownScript.FadeFlashVR(1.0, FadeDir.Out);
}
FallingLaunch.secondsAlive = (Time.time - lifeStartTime);
if (audioDeath) {audioDeath.Play();}
FallingLaunch.Analytics.Event(
"Death:Collision:" + FallingLaunch.vrModeAnalyticsString + Application.loadedLevelName + ":" + FallingLaunch.thisLevelArea,
FallingLaunch.secondsAlive
);
//Debug.Log("you died in the area " + FallingLaunch.thisLevelArea);
//Debug.Log("You died in a fatal collision with " + collision.gameObject);
yield DeathRespawn ();
}
}
}
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("Score")){
// Debug.Log("You scored!");
if (FallingLaunch.isVRMode) {
ScoreFlashVR(0.8, FadeDir.Out);
} else {
ScoreFlashTextureScript.FadeFlash(0.8, FadeDir.Out);
}
script.IncrementScore(6);
UIscriptComponent.flashProgressBar(1);
if (audioScore) {
//Debug.Log(Random.Range(0,2));
myVol = ((MoveController.Slowdown / MoveController.maxSlowdown) * peakVol);
clipToPlay = Random.Range(0.3f, 0.9f);
pitchRand = Random.Range(0.98f,1.03f);
if (playAltScoreAudio) {
audioToPlay = audioScoreAlt;
playAltScoreAudio = false;
}
else {
audioToPlay = audioScore;
playAltScoreAudio = true;
}
audioToPlay.pitch = pitchRand;
//if (clipToPlay == 1) {audioToPlay = audioScoreAlt;}
if (clipToPlay > 0.6f) {
audioToPlay.panStereo = (-clipToPlay/2);
audioToPlay.volume = Mathf.Clamp(myVol, (peakVol/2), peakVol);
}
else {
audioToPlay.volume = clipToPlay;
audioToPlay.panStereo = (clipToPlay/2);
}
//audioToPlay.volume = Mathf.Clamp(myVol, (peakVol * .5), peakVol);
audioToPlay.Play();
}
//yield WaitForSeconds(.2);
// try using PlayClipAtPoint here so score sound fades away in 3D space as you fall?
// Camera.main.SendMessage("flashUp");
}
if (other.gameObject.CompareTag ("LevelEnd") && isExitingLevel == false) {
isExitingLevel = true;
isPausable = false;
var isNewGamePlus = (FallingLaunch.NewGamePlus) ? "new_game_plus" : "first_game";
FallingLaunch.secondsInLevel = (Time.time - levelStartTime);
FallingLaunch.Analytics.Event(
"LevelComplete:" + FallingLaunch.vrModeAnalyticsString + SceneManagement.SceneManager.GetActiveScene().name + ":" + isNewGamePlus,
FallingLaunch.secondsInLevel
);
// reset the level area identifier for analytics purposes:
FallingLaunch.thisLevelArea = "0-start";
// TestFlightUnity.TestFlight.PassCheckpoint( "LevelComplete:" + Application.loadedLevelName );
// to keep you from dying after you strike the levelend trigger
script.IncrementScore(25);
audioLevelEnd.Play();
// the lerpControlOut timer argument must be equal to, or just less than,
// the sum of levelComplete's first argument,
// in order to create a convincing slowdown lerp and UI/camera fadeout:
lerpControlOut(4.0);
if (FallingLaunch.isVRMode) {
WhiteFadeVR(3.0, FadeDir.Out);
}
// Handles 2D (non-VR) UI logic in its own conditional,
// plus saves progress, loads the next level, etc.
UIscriptComponent.LevelComplete(3.0, 1.5);
}
}
function ContinueFromLevelStartVR () {
FallingLaunch.shouldShowVRIntroUI = false;
// TODO: Fade out material here instead of toggling the whole object outright?
levelStartUIVR.SetActive(false);
rb.isKinematic = false;
isAlive = 1;
isPausable = true;
lerpControlIn(1.5);
}
@script AddComponentMenu("Scripts/FallingPlayer")