void Update() { if (currentProfile == null) { return; } var locationOffset = new Vector3( GetNoise(0, currentProfile.shakeSpeed) * currentProfile.xMovement, GetNoise(1, currentProfile.shakeSpeed) * currentProfile.yMovement, 0 ); locationOffset *= trauma; transform.position = _startPosition + locationOffset; var zRotationOffset = GetNoise(10, currentProfile.shakeSpeed) * currentProfile.zRotation; zRotationOffset *= (float)Math.Pow(trauma, 2); transform.localRotation = Quaternion.Euler(_startRotation.eulerAngles.x, _startRotation.eulerAngles.y, zRotationOffset); trauma -= (Time.deltaTime / currentProfile.duration); if (trauma <= 0) { currentProfile = null; transform.position = _startPosition; transform.localRotation = _startRotation; } }
public void Shake(CameraShakeProfile profile = null) { if (profile == null) { profile = cameraShakeProfile; } if (profile == null) { Debug.Log("Profile is null"); return; } currentProfile = profile; trauma = 1; }
private void Start() { _shaker = GetComponent <CameraShaker>(); _temporaryProfile = CameraShakeProfile.MakeProfile(Magnitude, Roughness, FadeInTime, FadeOutTime); }
/// <summary> /// Starts a camera shake using the given profile /// </summary> /// <param name="camera">this</param> /// <param name="profile">profile to use for the shake</param> public static void StartShake(this UnityEngine.Camera camera, CameraShakeProfile profile) { var shaker = camera.gameObject.GetOrAddComponent <CameraShaker>(); shaker.StartShake(profile); }
public static void ShakeOnce(CameraShakeProfile profile) { ShakeOnce(profile.duration, profile.speed, profile.amount); }