CameraShake

Camera shake is working now
This commit is contained in:
Noah4ever
2021-12-13 16:02:11 +01:00
parent a2ac91bf6e
commit b2b997307b
7 changed files with 174 additions and 49 deletions

View File

@@ -24,10 +24,6 @@ public class Player : NetworkBehaviour
private int kills;
private int deaths;
[SerializeField] GameObject playerNeck;
[SerializeField] Camera playerCamera;
public GameObject PlayerNeck { get => playerNeck; set => playerNeck = value; }
public Camera PlayerCamera { get => playerCamera; }
private void Start()
{

View File

@@ -101,12 +101,41 @@ public class ProcedualAnimationController : NetworkBehaviour
[SerializeField] GameObject HoldPoint;
public bool isAiming = false;
[Header("Camera Shake Info")]
[SerializeField] bool cameraShakeActive = true;
[SerializeField] Camera objectToMove;
[SerializeField] float cameraShakeDuration = 1f;
[SerializeField] AnimationCurve cameraShakeCurve;
Vector3[] positionMod = new Vector3[4];
public Quaternion[] rotationMod = new Quaternion[4];
public Transform GunRightHandREF { get => gunRightHandREF; set => gunRightHandREF = value; }
public Transform GunLeftHandREF { get => gunLeftHandREF; set => gunLeftHandREF = value; }
public void cameraShake() {
// If camera shake is not disabled
if (cameraShakeActive) {
// Start coroutine that shakes the camera
StartCoroutine(shaking());
}
}
private IEnumerator shaking() {
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);
}
yield return null;
}
public void walkAnimation()
{
playerAnimator.SetFloat("x", playerController.localVelocity.x / playerController.currentMaxSpeed);