Distance to grenade explosion camera shake

if you are close to the grenade you get more camera shake
This commit is contained in:
Noah4ever
2021-12-13 21:52:38 +01:00
parent b2b997307b
commit 0fc8c6e08c
6 changed files with 435 additions and 283 deletions

View File

@@ -529,26 +529,104 @@ MonoBehaviour:
cameraShakeActive: 1
objectToMove: {fileID: 6272346181657429395}
cameraShakeDuration: 1
cameraShakeCurve:
nearDistance: 8
nearCameraShakeCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: -0.4614612
value: 0.028004631
inSlope: -0.015037956
outSlope: -0.015037956
time: 0.025429735
value: 0.19971195
inSlope: -0.030253958
outSlope: -0.030253958
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0.28070113
outWeight: 0.24073574
- serializedVersion: 3
time: 1.4633081
value: -0.037871435
inSlope: -0.011502813
outSlope: -0.011502813
time: 0.49595714
value: 0.049771994
inSlope: -0.14560473
outSlope: -0.14560473
tangentMode: 0
weightedMode: 0
inWeight: 0.23245634
inWeight: 0.33333334
outWeight: 0.294024
- serializedVersion: 3
time: 1.0253906
value: -0.004508972
inSlope: -0.10252651
outSlope: -0.10252651
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
mediumDistance: 20
mediumCameraShakeCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: -0.0071792603
value: 0.09154791
inSlope: -0.12938052
outSlope: -0.12938052
tangentMode: 34
weightedMode: 0
inWeight: 0
outWeight: 0.33333334
- serializedVersion: 3
time: 0.46580023
value: 0.030353572
inSlope: -0.067838416
outSlope: -0.067838416
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.27531913
- serializedVersion: 3
time: 0.9916687
value: 0.009421289
inSlope: -0.03980517
outSlope: -0.03980517
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
farDistance: 32
farCameraShakeCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: -0.0015304685
value: 0.033563316
inSlope: -0.05884709
outSlope: -0.05884709
tangentMode: 34
weightedMode: 0
inWeight: 0
outWeight: 0.33333334
- serializedVersion: 3
time: 0.48366547
value: 0.0050109476
inSlope: -0.02547526
outSlope: -0.02547526
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.5573828
- serializedVersion: 3
time: 1.0192597
value: -0.000051796436
inSlope: -0.009452574
outSlope: -0.009452574
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2

View File

@@ -760,7 +760,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explosionForce
value: 600
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explodeParticle
@@ -768,7 +768,7 @@ PrefabInstance:
objectReference: {fileID: 842071826}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: cameraShakeRadius
value: 200
value: 50
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: lengthOfExplosion
@@ -2557,7 +2557,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explosionForce
value: 600
value: 850
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explodeParticle
@@ -2569,7 +2569,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: cameraShakeRadius
value: 200
value: 50
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: lengthOfExplosion
@@ -4257,7 +4257,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -8.740173, y: 68.40698}
m_AnchoredPosition: {x: -8.740234, y: 68.40698}
m_SizeDelta: {x: 182.68939, y: 68.40671}
m_Pivot: {x: 1, y: 1}
--- !u!114 &1430445133
@@ -5690,7 +5690,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explosionForce
value: 600
value: 900
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explodeParticle
@@ -5698,7 +5698,7 @@ PrefabInstance:
objectReference: {fileID: 842071826}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: cameraShakeRadius
value: 200
value: 50
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: lengthOfExplosion

View File

@@ -105,7 +105,13 @@ public class ProcedualAnimationController : NetworkBehaviour
[SerializeField] bool cameraShakeActive = true;
[SerializeField] Camera objectToMove;
[SerializeField] float cameraShakeDuration = 1f;
[SerializeField] AnimationCurve cameraShakeCurve;
[SerializeField] int nearDistance = 5;
[SerializeField] AnimationCurve nearCameraShakeCurve;
[SerializeField] int mediumDistance = 15;
[SerializeField] AnimationCurve mediumCameraShakeCurve;
[SerializeField] int farDistance = 25;
[SerializeField] AnimationCurve farCameraShakeCurve;
private AnimationCurve cameraShakeCurve;
Vector3[] positionMod = new Vector3[4];
public Quaternion[] rotationMod = new Quaternion[4];
@@ -113,26 +119,44 @@ public class ProcedualAnimationController : NetworkBehaviour
public Transform GunRightHandREF { get => gunRightHandREF; set => gunRightHandREF = value; }
public Transform GunLeftHandREF { get => gunLeftHandREF; set => gunLeftHandREF = value; }
public void cameraShake() {
public void cameraShake(float distance) {
// If camera shake is not disabled
if (cameraShakeActive) {
// Start coroutine that shakes the camera
StartCoroutine(shaking());
StartCoroutine(shaking(distance));
}
}
private IEnumerator shaking() {
private IEnumerator shaking(float distance) {
float elapsedTime = 0f;
while (elapsedTime < cameraShakeDuration) {
// Time increment
elapsedTime += Time.deltaTime;
// Getting strength value from curve at current time
float strength = cameraShakeCurve.Evaluate(elapsedTime / cameraShakeDuration);
// Move object
objectToMove.transform.localPosition = objectToMove.transform.localPosition + Random.insideUnitSphere * strength;
// Wait
yield return new WaitForSeconds(Time.deltaTime);
bool cameraShake = true;
// Getting right camera shake curve
if(distance < nearDistance) {
cameraShakeCurve = nearCameraShakeCurve; // high camera shake
Debug.Log("NEAR EXPLOSION: " + distance);
} else if(distance < mediumDistance){
cameraShakeCurve = mediumCameraShakeCurve; // medium camera shake
Debug.Log("MEDIUM EXPLOSION: " + distance);
} else if(distance < farDistance) {
cameraShakeCurve = farCameraShakeCurve; // little camera shake
Debug.Log("FAR EXPLOSION: " + distance);
} else { // If distance is even further than far then no camera shake
cameraShake = false;
}
if (cameraShake) {
while (elapsedTime < cameraShakeDuration) {
// Time increment
elapsedTime += Time.deltaTime;
// Getting strength value from curve at current time
float strength = cameraShakeCurve.Evaluate(elapsedTime / cameraShakeDuration);
// Move object
objectToMove.transform.localPosition = objectToMove.transform.localPosition + Random.insideUnitSphere * strength;
// Wait
yield return new WaitForSeconds(Time.deltaTime);
}
}
yield return null;
}

View File

@@ -66,7 +66,7 @@ public class Grenade : MonoBehaviour
if (nearbyObject.GetComponent<Player>() && nearbyObject.GetType() != typeof(UnityEngine.CharacterController)) {
// Starts camera shake on player
float distance = Vector3.Distance(transform.position, nearbyObject.transform.position);
nearbyObject.GetComponent<ProcedualAnimationController>().cameraShake();
nearbyObject.GetComponent<ProcedualAnimationController>().cameraShake(distance);
}
}
yield return null;