コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            CameraShake();
        }

        if (shake)
        {
            if (shakeTimer > shakeTime * Time.timeScale)
            {
                shakeTimer     = 0;
                shake          = false;
                Time.timeScale = 1;

                Camera.main.transform.position = new Vector3(originalPosition.x, originalPosition.y, originalPosition.z);
            }
            else
            {
                shakeTimer += Time.deltaTime;
                Camera.main.transform.position = originalPosition + Vector3.Scale(SmoothRandom.GetVector3(shakeSpeedCounter--), shakeRange);

                shakeSpeedCounter *= -1;

                shakeRange = new Vector3(shakeRange.x * -1, shakeRange.y * -1);
            }
        }
    }
コード例 #2
0
 void Update()
 {
     if (positionShakeSpeed > 0)
     {
         transform.localPosition = position + Vector3.Scale(SmoothRandom.GetVector3(positionShakeSpeed), positionShakeRange);
     }
 }
コード例 #3
0
ファイル: CameraShake.cs プロジェクト: pitsikalis/GSS_Master
        public void DirectShake(float frequency, float amplitude)
        {
            transform.eulerAngles -= tMovement;

            tMovement = Vector3.Scale(SmoothRandom.GetVector3(frequency * Time.time), shakeRange) * amplitude;

            transform.eulerAngles += tMovement;
        }
コード例 #4
0
        public override void Execute(float currentTime)
        {
            var rotation = Quaternion.Euler(localRotation.eulerAngles + Vector3.Scale(SmoothRandom.GetVector3(shakeValue), new Vector3(4.0f, 4.0f, 4.0f)));

            actor.transform.localRotation = rotation;

            actor.transform.localPosition = localPosition + Vector3.Scale(SmoothRandom.GetVector3(shakeValue), new Vector3(0.1f, 0.1f, 0.1f));
        }
コード例 #5
0
 public void ShakePosition()
 {
     /*
      * Update the localPosition by taking the original localPosition and adding a scaled Vector3.
      * The Vector3 is calculated by calling the SmoothRandom.GetVector3 function from the Perlin
      * script, which returns a pseudo-random Vector3 based on the given inputs.
      */
     transform.localPosition = position + Vector3.Scale(SmoothRandom.GetVector3(positionShakeSpeed), positionShakeRange);
 }
コード例 #6
0
ファイル: OrganismC.cs プロジェクト: bekpsmith/pixelplacement
    void Update()
    {
        _transform.position = initPos + Vector3.Scale(SmoothRandom.GetVector3(speed), range);
        Vector3    randomRot = Vector3.Scale(SmoothRandom.GetVector3(speed), range);
        Quaternion newRot    = new Quaternion();

        newRot.x            = initRot.x + randomRot.x;
        newRot.y            = initRot.y + randomRot.y;
        newRot.z            = initRot.z + randomRot.z;
        _transform.rotation = newRot;
    }
コード例 #7
0
        void Randomize()
        {
            if (!update)
            {
                return;
            }
            Vector3 v = SmoothRandom.GetVector3(randomSpeed);

            v.Scale(randomScale);
            steer.TargetPoint = v + offset;
        }
コード例 #8
0
    //constant spring force.
    void UpdateEarthQuake()
    {
        if (m_client == null || !m_client.UseEarthQuake || m_earthQuakeTimeTemp <= 0.0f || !EarthQuakeToggled)
        {
            return;
        }

        m_elapsedTime += Time.deltaTime;

        m_earthQuakeTimeTemp -= 0.0166f * (60 * Time.deltaTime);

        float magnitude = 0f;

        if (m_client.EarthQuakeMagTye == MAGTYPE.Fixed)
        {
            magnitude = m_client.EarthQuakeMagnitude;
        }
        else
        {
            magnitude = m_client.EarthQuakeMagCurve.Evaluate(m_elapsedTime);
        }

        // the horisontal move is a perlin noise value between 0 and
        // 'EarthQuakeMagnitude' (depending on 'EarthQuakeTime').
        // horizMove will ease out during the last second.
        Vector3 horizMove = Vector3.Scale(SmoothRandom.GetVector3Centered(1), new Vector3(magnitude,
                                                                                          0, magnitude)) * Mathf.Min(m_earthQuakeTimeTemp, 1.0f);

        // the vertical move is half the earthquake magnitude and
        // has a 30% chance of occuring each frame. when it does,
        // it alternates between positive and negative. this produces
        // sharp shakes with nice spring smoothness inbetween.
        // vertMove will ease out during the last second.
        float vertMove = 0;

        if (UnityEngine.Random.value < 0.3f)
        {
            vertMove = UnityEngine.Random.Range(0, (magnitude * 0.35f)) * Mathf.Min(m_earthQuakeTimeTemp, 1.0f);
            if (PositionSpring.State.y >= PositionSpring.RestState.y)
            {
                vertMove = -vertMove;
            }
        }

        PositionSpring.AddForce(horizMove);

        // apply earthquake roll force on the camera rotation spring
        RotationSpring.AddForce(new Vector3(0, 0, -horizMove.x * 2) * m_client.EarthQuakeCameraRollFactor);

        // vertical move is always applied to the camera spring.
        PositionSpring.AddForce(new Vector3(0, vertMove, 0));
    }
コード例 #9
0
ファイル: CameraShake.cs プロジェクト: pturner42/VGDesign
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.K))
        {
            CamShake();
        }
        else
        {
            isShake = false;
        }

        if (isShake)
        {
            shake = SmoothRandom.GetVector3(shakeSpeed--);
            Camera.main.transform.position = originalCamPos + Vector3.Scale(new Vector3(shake.x, shake.y), shakeRange);

            shakeSpeed *= -1;
            shakeRange  = new Vector3(shakeRange.x *= -1, shakeRange.y);
        }
    }
コード例 #10
0
    IEnumerator Shaker(float duration, float strength, float frequency)
    {
        float endTime = Time.time + duration;

        while (Time.time < endTime)
        {
            if (Random.Range(0f, 1f) > 0.5f)
            {
                shakeOffset.y = -(SmoothRandom.GetVector3(20).normalized *((Time.time / endTime) * strength)).y;
            }
            else
            {
                shakeOffset.y = (SmoothRandom.GetVector3(20).normalized *((Time.time / endTime) * strength)).y;
            }

            transform.position = cameraStartPos + (Vector3)shakeOffset;

            yield return(new WaitForSeconds(Random.Range(frequency - frequencyVariance, frequency + frequencyVariance)));
        }

        transform.position = cameraStartPos;
        yield return(null);
    }
コード例 #11
0
    void Update()
    {
        float fVertical   = Input.GetAxis("Vertical");
        float fHorizontal = Input.GetAxis("Horizontal");

        if (fVertical != 0.0f || fHorizontal != 0.0f)
        {
            Vector3 tMove = ((m_tMoveForward * fVertical) + (transform.right * fHorizontal)) * m_fCameraSpeed;

            if (fVertical != 0.0f && fHorizontal != 0.0f)
            {
                tMove = tMove.normalized * m_fCameraSpeed;
            }

            tMove            *= Time.deltaTime;
            m_tStartShakePos += tMove;
        }

        transform.position = Vector3.Lerp(transform.position, m_tStartShakePos, m_fCameraSpeed * Time.deltaTime);


        if (m_bShaking)
        {
            if ((Time.fixedTime - m_fShakeTimer) >= m_fShakeDuration)
            {
                m_fShakeTimer = 0.0f;
                m_bShaking    = false;
            }

            else
            {
                transform.position    = m_tStartShakePos + Vector3.Scale(SmoothRandom.GetVector3(m_fCurrentShakeSpeed--), m_tShakeRange);
                m_fCurrentShakeSpeed *= -1.0f;
            }
        }
    }
 void Update()
 {
     Camera.main.transform.localPosition = SmoothRandom.GetVector3(speed) * movement;
     Camera.main.transform.LookAt(Camera.main.transform.parent.position + Camera.main.transform.parent.forward * 100 + SmoothRandom.GetVector3(speed) * rotation);
 }
コード例 #13
0
    public virtual void Update()
    {
        this.transform.rotation = Quaternion.LookRotation(new Vector3(1, 0.5f, 0.5f) + ((SmoothRandom.GetVector3(this.movementSpeed) - (Vector3.one * 0.3f)) * this.movementAmount));
        if ((this.mouseOver == -1) && (Time.time > this.nextChangeTime))
        {
            int curP = this.p;
            int curN = this.n;

            var displayNucleons = this.display.GetNucleons();
            if (displayNucleons != null && displayNucleons.Length > 0)
            {
                int i = 0;
                while (i < displayNucleons.Length)
                {
                    bool isProton = ((Random.value < (UnityScript.Lang.UnityBuiltins.parseFloat(this.p) / (this.p + this.n))) && (curP > 0)) || (curN == 0);
                    displayNucleons[i].color = isProton ? this.protonColor : this.neutronColor;
                    if (isProton)
                    {
                        curP--;
                    }
                    else
                    {
                        curN--;
                    }
                    i++;
                }
                this.display.SetNucleons(displayNucleons);
            }

            this.nextChangeTime = Time.time + this.changeInterval;
        }
        if ((this.lastP != this.p) || (this.lastN != this.n))
        {
            this.Rebuild();
            this.lastP = this.p;
            this.lastN = this.n;
        }
    }
コード例 #14
0
ファイル: SmoothRandom.cs プロジェクト: atom-chen/rongyaojt
    public static float Get(float speed)
    {
        float num = Time.time * 0.01f * speed;

        return(SmoothRandom.Get().HybridMultifractal(num * 0.01f, 15.7f, 0.65f));
    }
コード例 #15
0
ファイル: SmoothRandom.cs プロジェクト: atom-chen/rongyaojt
    public static Vector3 GetVector3(float speed)
    {
        float x = Time.time * 0.01f * speed;

        return(new Vector3(SmoothRandom.Get().HybridMultifractal(x, 15.73f, 0.58f), SmoothRandom.Get().HybridMultifractal(x, 63.94f, 0.58f), SmoothRandom.Get().HybridMultifractal(x, 0.2f, 0.58f)));
    }
コード例 #16
0
        /// <summary>
        /// Updates the effect.
        /// </summary>
        public override void Update()
        {
            // Stop the effect if it has occurred for more than the duration.
            var endTime = m_StartTime + m_Duration;

            if (endTime < Time.unscaledTime)
            {
                StopEffect();
                return;
            }

            var force = Vector3.zero;

            if (m_SmoothHorizontalForce)
            {
                // Apply a horizontal force which is the perlin noise value between 0 and the force. This force will ease out during the specified fade out duration.
                force.x = SmoothRandom.GetVector3Centered(1).x *m_Force.x *Mathf.Min(endTime - Time.unscaledTime, m_FadeOutDuration) * Time.timeScale * m_CharacterLocomotion.TimeScale;
            }
            else
            {
                // If smooth horizontal force is false then apply a random force which will ease out during the specified fade out duration.
                force.x = Random.Range(-m_Force.x, m_Force.x) * Mathf.Min(endTime - Time.unscaledTime, m_FadeOutDuration);

                // Alternates between positive and negative to produce sharp shakes with nice spring smoothness.
                if (Mathf.Sign(m_TotalForce.x) == Mathf.Sign(force.x))
                {
                    force.x = -force.x;
                }
            }

            // Restrict the number of times a vertical force is applied to prevent a jerky movements.
            if (Random.value <= m_VerticalForceProbability)
            {
                // Smoothly fade out during the specified fade out duration.
                force.y = Random.Range(0, m_Force.y) * Mathf.Min(endTime - Time.unscaledTime, m_FadeOutDuration);

                // Alternates between positive and negative to produce sharp shakes with nice spring smoothness.
                if (Mathf.Sign(m_TotalForce.y) == Mathf.Sign(force.y))
                {
                    force.y = -force.y;
                }
            }

            m_TotalForce += force;

            // Add the force to the camera.
            if ((m_Target & ShakeTarget.Camera) != 0 && m_CameraController != null)
            {
                m_CameraController.AddPositionalForce(force * m_PositionalFactor);
                m_CameraController.AddRotationalForce(-force * 2 * m_RotationalFactor);
            }

            // Add the force to the item.
            if ((m_Target & ShakeTarget.Item) != 0)
            {
                var positionalForce = Vector3.forward * force.x * 0.015f;
                var rotationalForce = positionalForce;
                rotationalForce.Set(force.y * 2, -force.x, force.x * 2);
                EventHandler.ExecuteEvent(m_GameObject, "OnAddSecondaryForce", -1, positionalForce, rotationalForce, true);
            }

            // Add the horizontal force to the character.
            if ((m_Target & ShakeTarget.Character) != 0)
            {
                force.y = 0;
                m_CharacterLocomotion.AddForce(force * m_PositionalFactor);
            }
        }
コード例 #17
0
 void Update()
 {
     transform.position = position + Vector3.Scale(SmoothRandom.GetVector3(speed), range);
 }
コード例 #18
0
ファイル: BlurryVision.cs プロジェクト: joenarus/Stressident
    private void Update()
    {
        if (stressed)
        {
            blurCountdown -= Time.deltaTime;
            if (blurCountdown < 0)
            {
                CameraBlur();
                blurCountdown = timeBetweenBlurs;
            }
        }

        if (blur)
        {
            if (blurTimer > blurTime * Time.timeScale)
            {
                blurTimer      = 0;
                blur           = false;
                Time.timeScale = 1;

                Camera.main.transform.position = new Vector3(originalCameraPosition.x, Camera.main.transform.position.y, originalCameraPosition.z);
            }
            else
            {
                blurTimer += Time.deltaTime;
                Camera.main.transform.position = originalCameraPosition + Vector3.Scale(SmoothRandom.GetVector2(blurSpeed--), blurRange);
                blurSpeed *= -1;
                blurRange  = new Vector3(blurRange.x * -1, blurRange.y);
            }
        }
    }
コード例 #19
0
 public void ShakeRotation()
 {
     /*
      * This set rotationQuat equal to a pseudo-random rotation by taking the initial rotation(in Euler Angle format)
      * and adding a scaled Vector3 to it. The Vector3 is created by calling the SmoothRandom.GetVector3 function from
      * the Perlin script and multiplying the resultant Vector3 by the range to shake across. Then update the localRotation
      * to the new rotationQuat value.
      *
      */
     rotationQuat            = Quaternion.Euler(initialRotation.eulerAngles + Vector3.Scale(SmoothRandom.GetVector3(rotationShakeSpeed), rotationShakeRange));
     transform.localRotation = rotationQuat;
 }