add camera shake

This commit is contained in:
Cat Flynn 2021-01-09 18:18:55 +00:00
parent af752bdb68
commit cc2150a88e
13 changed files with 196 additions and 6 deletions

33
Assets/CameraShake.cs Normal file
View File

@ -0,0 +1,33 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ktyl.Util;
using UnityEngine;
public class CameraShake : MonoBehaviour
{
[SerializeField] private SerialFloat _intensity;
[SerializeField] private SerialFloat _duration;
[SerializeField] private AnimationCurve _anim;
private float _start = -1;
private void Awake()
{
Shader.SetGlobalFloat("_CameraShake", 0);
}
void LateUpdate()
{
var elapsed = Time.time - _start;
if (elapsed > _duration) return;
var normalisedElapsed = elapsed / _duration;
Shader.SetGlobalFloat("_CameraShake", _anim.Evaluate(normalisedElapsed) * _intensity);
}
public void Shake()
{
_start = Time.time;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3147f962613cca54f8a0b78929a2854b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Data.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3463a456983d7f843832019b8cf97a5c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d86361ffc5ae478d9e976629c5d651bd, type: 3}
m_Name: Camera Shake Duration
m_EditorClassIdentifier:
_initialValue: 0.5
_readOnly: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 650f42715fd5234439ee753fd4bcb106
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d86361ffc5ae478d9e976629c5d651bd, type: 3}
m_Name: Camera Shake Intensity
m_EditorClassIdentifier:
_initialValue: 0.2
_readOnly: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a9fdc2c236f2e264a8e573af06ca295d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -115,7 +115,7 @@ Material:
- _Color1: {r: 0.5411765, g: 1.8509804, b: 2, a: 1} - _Color1: {r: 0.5411765, g: 1.8509804, b: 2, a: 1}
- _Color2: {r: 1.2078432, g: 0, b: 1.1058824, a: 1} - _Color2: {r: 1.2078432, g: 0, b: 1.1058824, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _FlashColor: {r: 1.1, g: 1.1, b: 1.1, a: 1} - _FlashColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []
--- !u!114 &1642389398374086642 --- !u!114 &1642389398374086642

View File

@ -549,6 +549,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 3397488661916228001} - component: {fileID: 3397488661916228001}
- component: {fileID: 5076175860835241000}
m_Layer: 0 m_Layer: 0
m_Name: Tunnel m_Name: Tunnel
m_TagString: Untagged m_TagString: Untagged
@ -572,6 +573,44 @@ Transform:
m_Father: {fileID: 3397488660859550701} m_Father: {fileID: 3397488660859550701}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5076175860835241000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3397488661916228000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3147f962613cca54f8a0b78929a2854b, type: 3}
m_Name:
m_EditorClassIdentifier:
_intensity: {fileID: 11400000, guid: a9fdc2c236f2e264a8e573af06ca295d, type: 2}
_duration: {fileID: 11400000, guid: 650f42715fd5234439ee753fd4bcb106, type: 2}
_anim:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: -2
outSlope: -2
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 0
inSlope: -0
outSlope: -0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &3859152818583472155 --- !u!1 &3859152818583472155
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -277,6 +277,49 @@ MonoBehaviour:
pauseOnBeat: 16 pauseOnBeat: 16
pauseLengthInBeats: 0 pauseLengthInBeats: 0
beatOffset: 2 beatOffset: 2
--- !u!1 &531937973 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3397488661916228000, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
m_PrefabInstance: {fileID: 1077224733}
m_PrefabAsset: {fileID: 0}
--- !u!114 &531937974
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 531937973}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3147f962613cca54f8a0b78929a2854b, type: 3}
m_Name:
m_EditorClassIdentifier:
_intensity: {fileID: 11400000, guid: a9fdc2c236f2e264a8e573af06ca295d, type: 2}
_duration: {fileID: 11400000, guid: 650f42715fd5234439ee753fd4bcb106, type: 2}
_anim:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: -2
outSlope: -2
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 0
inSlope: -0
outSlope: -0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &728836291 --- !u!1 &728836291
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -499,7 +542,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_LocalScale.x propertyPath: m_LocalScale.x
value: 2309.1313 value: 2303.7488
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_LocalScale.y propertyPath: m_LocalScale.y
@ -763,6 +806,7 @@ MonoBehaviour:
- {fileID: 1611642542} - {fileID: 1611642542}
- {fileID: 728836294} - {fileID: 728836294}
polygon: {fileID: 1639649353} polygon: {fileID: 1639649353}
_cameraShake: {fileID: 0}
--- !u!1 &1215971662 --- !u!1 &1215971662
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -43,6 +43,8 @@ public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
private void Awake() private void Awake()
{ {
DOTween.Init();
_secPerBeat = 60f / bpm; _secPerBeat = 60f / bpm;
RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup); RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup);
RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _); RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _);

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DG.Tweening; using DG.Tweening;
using Ktyl.Util;
using UnityEngine; using UnityEngine;
using Weapons.Scripts; using Weapons.Scripts;
@ -10,6 +11,8 @@ public class LoseLife : MonoBehaviour
[SerializeField] private Renderer[] healthMarkers; [SerializeField] private Renderer[] healthMarkers;
[SerializeField] private Renderer polygon; [SerializeField] private Renderer polygon;
[SerializeField] private CameraShake _cameraShake;
private EntityHealth _health; private EntityHealth _health;
private void Awake() private void Awake()
@ -32,6 +35,8 @@ public class LoseLife : MonoBehaviour
sequence.Append(polygon.material.DOFloat(0,"_FlashAmount", 0.2f).SetUpdate(true)); sequence.Append(polygon.material.DOFloat(0,"_FlashAmount", 0.2f).SetUpdate(true));
} }
_cameraShake.Shake();
sequence.Play().OnComplete(() => sequence.Play().OnComplete(() =>
{ {
_health.enabled = true; _health.enabled = true;

View File

@ -27,7 +27,7 @@ Shader "custom/tunnel"
_StarMap("Star Map", 2D) = "black" _StarMap("Star Map", 2D) = "black"
_FractalMap("Fractal Map", 2D) = "black" _FractalMap("Fractal Map", 2D) = "black"
_ShakeStrength("Shake Strength", Float) = 0.01 // _ShakeStrength("Shake Strength", Float) = 0.01
_Intensity("Intensity", Float) = 1.0 _Intensity("Intensity", Float) = 1.0
} }
@ -79,7 +79,7 @@ Shader "custom/tunnel"
float _StarsWeight; float _StarsWeight;
float _Intensity; float _Intensity;
float _ShakeStrength; float _CameraShake = 0.0;
TEXTURE2D(_NebulaMap); TEXTURE2D(_NebulaMap);
SAMPLER(sampler_NebulaMap); SAMPLER(sampler_NebulaMap);
@ -202,8 +202,8 @@ Shader "custom/tunnel"
float shake = _Time*50; float shake = _Time*50;
cameraShake.x = cos(shake*12.3341)+sin(shake*19.231057); cameraShake.x = cos(shake*12.3341)+sin(shake*19.231057);
cameraShake.y = cos(shake*17.12311)+sin(shake*14.2315165); cameraShake.y = cos(shake*17.12311)+sin(shake*14.2315165);
cameraShake*=_ShakeStrength; cameraShake*=_CameraShake;
// p += cameraShake; p += cameraShake;
// shared tunnel vars // shared tunnel vars
float r = length(p); float r = length(p);