void Update() { var sin = Mathf.Sin(2 * Mathf.PI * Speed * Time.time) * MoveRange; if (Input.GetKeyDown(KeyCode.Space)) { if (shakeMode == ShakeMode.Y) { Target.position = startpos; shakeMode = ShakeMode.X; } else { Target.position = startpos; shakeMode = ShakeMode.Y; } } if (shakeMode == ShakeMode.Y) { Target.position = new Vector3(startpos.x, startpos.y + sin, startpos.z); } else { Target.position = new Vector3(startpos.x + sin, startpos.y, startpos.z); } }
public static void Shake(float duration, float power, ShakeMode mode) { if(percentComplete == 1) originalPos = tr.localPosition; i_Mode = mode; elapsed = 0; i_Duration = duration; i_Power = power; }
public static void Shake(float duration, float power, ShakeMode mode) { if (percentComplete == 1) { originalPos = tr.localPosition; } i_Mode = mode; elapsed = 0; i_Duration = duration; i_Power = power; }
public static void Shake(float duration, float power, ShakeMode mode) { if (percentComplete == 1) { originalPos = m_transform.localPosition; } m_mode = mode; elapsed = 0; m_duration = duration; m_power = power; }
public static void Shake(float duration, float power, ShakeMode mode) // Убрать static для работы shake в разных местах. TO DO { if (percentComplete == 1) { originalPos = tr.localPosition; } i_Mode = mode; elapsed = 0; i_Duration = duration; i_Power = power; }
public static void Shake(float duration, float power, ShakeMode mode) { if (_percentComplete == 1) { _originalPos = _transform.localPosition; } _mode = mode; _elapsed = 0; _duration = duration; _power = power; }
// BUSINESS LOGIC public void ForceShake(float i_ShakeTime, float i_Amount, ShakeMode i_ShakeMode, Action i_Callback = null) { bool screenShakeEnabled; GameSettings.TryGetBoolMain(Settings.s_ScreenshakeSetting, out screenShakeEnabled); if (!screenShakeEnabled) { return; } OnScreenShake(i_ShakeTime, i_Amount, i_ShakeMode, i_Callback); }
private void OnScreenShake(float i_ShakeTime, float i_Amount, ShakeMode i_ShakeMode, Action i_Callback) { if (i_ShakeMode == ShakeMode.Interruput) { EndShake(); } else { // DontInterrupt } StartShake(i_ShakeTime, i_Amount, i_Callback); }
public static void Shake(float duration, float power) { stop = false; if (percentComplete == 1) { originalPos = tr.localPosition; } i_Mode = ShakeMode.XYZ; elapsed = 0; i_Duration = duration; i_Power = power; }
public void Shake(ShakeMode mode, Vector2 dir, SmoothFunc smoothFunc = null, float trauma = 1f) { int seed = Random.Range(-100, 100); CameraShakeData data = new CameraShakeData { trauma = trauma, force = shakeForces[(int)mode], speed = shakeSpeeds[(int)mode], seed = seed, dir = dir, smoothFunc = smoothFunc ?? MathUtils.SmoothStart2 }; shakeData[shakeDataCount++] = data; Debug.Assert(shakeDataCount <= shakeData.Length, "Shake data is full"); }
public void Shake(float magnitude, float duration, ShakeMode mode, ShakeAxis options) { if (IsShaking) { _shakeDuration += duration; } else { IsShaking = true; _shakeMagnitude = magnitude; _shakeMode = mode; _shakeOptions = options; _shakeDuration = duration; _shakeAnchorPosition = _position; _shakeSpeed = 600f; _shakeDistance = 30f; _shakeAngle = 1.5707963267948966f; } }
/// <summary> /// Shake camera with given magnitude, duration and shake mode /// </summary> private IEnumerator Shake(float magnitude, float duration, ShakeMode shakeMode) { float elapsed = 0.0f; while (elapsed < duration) { elapsed += Time.deltaTime; float percentComplete = elapsed / duration; float damper = 1.0f - Mathf.Clamp(4.0f * percentComplete - 3.0f, 0.0f, 1.0f); // map value to [-1, 1] float x = Random.value * 2.0f - 1.0f; float y = Random.value * 2.0f - 1.0f; float z = Random.value * 2.0f - 1.0f; x *= magnitude * damper; y *= magnitude * damper; z *= magnitude * damper; if (shakeMode == ShakeMode.Horizontal) { m_CameraTransform.localPosition = new Vector3(x, m_InitialLocalPosition.y, z); } else if (shakeMode == ShakeMode.Vertical) { y = Mathf.Abs(y); m_CameraTransform.localPosition = new Vector3(m_InitialLocalPosition.x, y, m_InitialLocalPosition.z); } else if (shakeMode == ShakeMode.AllDirections) { m_CameraTransform.localPosition = new Vector3(x, y, z); } else { m_CameraTransform.localPosition = new Vector3(m_InitialLocalPosition.x, m_InitialLocalPosition.y, z); } yield return(null); } m_CameraTransform.localPosition = m_InitialLocalPosition; }
/// <summary> /// Camera shake /// </summary> public void CameraShake(float magnitude, float duration, ShakeMode shakeMode) { StartCoroutine(Shake(magnitude, duration, shakeMode)); }
public void Shake(ShakeMode mode, SmoothFunc smoothFunc = null, float trauma = 1f) => Shake(mode, Vector2.zero, smoothFunc, trauma);
public static Vector3 GetOffset(EffectContext context, float time, PingPongValues values, ShakeMode mode, ContinousModularFloat intensity, ShakeDimension dimensions) { Vector3 direction; switch (mode) { case ShakeMode.PingPong: direction = Vector3.one; values.Affect(ref direction); break; case ShakeMode.Random: direction = new Vector3( UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value ); break; default: throw new ArgumentOutOfRangeException("mode", mode, null); } direction.Normalize(); if ((dimensions & ShakeDimension.FirstDimension) != ShakeDimension.FirstDimension) { direction.x = 0; } if ((dimensions & ShakeDimension.SecondDimension) != ShakeDimension.SecondDimension) { direction.y = 0; } if ((dimensions & ShakeDimension.ThirdDimension) != ShakeDimension.ThirdDimension) { direction.z = 0; } return(direction * intensity.Evaluate(context, time)); }