You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.5 KiB

7 years ago
  1. #if !UNITY_FLASH
  2. using UnityEngine;
  3. using System.Collections;
  4. using DentedPixel;
  5. public class GeneralCameraShake : MonoBehaviour {
  6. private GameObject avatarBig;
  7. private float jumpIter = 9.5f;
  8. private AudioClip boomAudioClip;
  9. // Use this for initialization
  10. void Start () {
  11. avatarBig = GameObject.Find("AvatarBig");
  12. AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(8.130963E-06f, 0.06526042f, 0f, -1f), new Keyframe(0.0007692695f, 2.449077f, 9.078861f, 9.078861f), new Keyframe(0.01541314f, 0.9343268f, -40f, -40f), new Keyframe(0.05169491f, 0.03835937f, -0.08621139f, -0.08621139f));
  13. AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003005181f, 0f, 0f), new Keyframe(0.01507768f, 0.002227979f, 0f, 0f));
  14. boomAudioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.1f,0f,0f)} ));
  15. bigGuyJump();
  16. }
  17. void bigGuyJump(){
  18. float height = Mathf.PerlinNoise(jumpIter, 0f)*10f;
  19. height = height*height * 0.3f;
  20. // Debug.Log("height:"+height+" jumpIter:"+jumpIter);
  21. LeanTween.moveY(avatarBig, height, 1f).setEase(LeanTweenType.easeInOutQuad).setOnComplete( ()=>{
  22. LeanTween.moveY(avatarBig, 0f, 0.27f).setEase(LeanTweenType.easeInQuad).setOnComplete( ()=>{
  23. LeanTween.cancel(gameObject);
  24. /**************
  25. * Camera Shake
  26. **************/
  27. float shakeAmt = height*0.2f; // the degrees to shake the camera
  28. float shakePeriodTime = 0.42f; // The period of each shake
  29. float dropOffTime = 1.6f; // How long it takes the shaking to settle down to nothing
  30. LTDescr shakeTween = LeanTween.rotateAroundLocal( gameObject, Vector3.right, shakeAmt, shakePeriodTime)
  31. .setEase( LeanTweenType.easeShake ) // this is a special ease that is good for shaking
  32. .setLoopClamp()
  33. .setRepeat(-1);
  34. // Slow the camera shake down to zero
  35. LeanTween.value(gameObject, shakeAmt, 0f, dropOffTime).setOnUpdate(
  36. (float val)=>{
  37. shakeTween.setTo(Vector3.right*val);
  38. }
  39. ).setEase(LeanTweenType.easeOutQuad);
  40. /********************
  41. * Shake scene objects
  42. ********************/
  43. // Make the boxes jump from the big stomping
  44. GameObject[] boxes = GameObject.FindGameObjectsWithTag("Respawn"); // I just arbitrarily tagged the boxes with this since it was available in the scene
  45. foreach (GameObject box in boxes) {
  46. box.GetComponent<Rigidbody>().AddForce(Vector3.up * 100 * height);
  47. }
  48. // Make the lamps spin from the big stomping
  49. GameObject[] lamps = GameObject.FindGameObjectsWithTag("GameController"); // I just arbitrarily tagged the lamps with this since it was available in the scene
  50. foreach (GameObject lamp in lamps) {
  51. float z = lamp.transform.eulerAngles.z;
  52. z = z > 0.0f && z < 180f ? 1 : -1; // push the lamps in whatever direction they are currently swinging
  53. lamp.GetComponent<Rigidbody>().AddForce(new Vector3(z, 0f, 0f ) * 15 * height);
  54. }
  55. // Play BOOM!
  56. LeanAudio.play(boomAudioClip, transform.position, height*0.2f); // Like this sound? : http://leanaudioplay.dentedpixel.com/?d=a:fvb:8,0,0.003005181,0,0,0.01507768,0.002227979,0,0,8~8,8.130963E-06,0.06526042,0,-1,0.0007692695,2.449077,9.078861,9.078861,0.01541314,0.9343268,-40,-40,0.05169491,0.03835937,-0.08621139,-0.08621139,8~0.1,0,0,~44100
  57. // Have the jump happen again 2 seconds from now
  58. LeanTween.delayedCall(2f, bigGuyJump);
  59. });
  60. });
  61. jumpIter += 5.2f;
  62. }
  63. }
  64. #endif