mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
CameraShake
Camera shake is working now
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user