Fade in and Fade Out Camera Shaking Effect Over Time

Hello Guys… I am Having Trouble for Making Fade In and Fade Out Effect For For Camer Shaking

As we know perline noise start from random value between 0,1 and then gives us smooth and random graph which is very good for camera shaking

but my problem is when i press button it starts the shaking camera for 5 seconds and then when i press button again it just takes random number then it goes shaking again smooth…

what i want to do is make fade effect so that camera start shake from last position when and keep shaking smoothly

this is basic scrip i am using using this basic script and i am have attached it with my FPS Controller

     public class ExampleClass : MonoBehaviour {
         public float heightScale = 1.0F;
         public float xScale = 1.0F;
         void Update() {
             float height = heightScale * Mathf.PerlinNoise(Time.time * xScale, 0.0F);
             Vector3 pos = transform.position;
             pos.y = height;
             transform.position = pos;
         }
     }

It would be very great if some one help me out

or can anyone please tell me how can i shake it back from the last position so i will not need any fade in and fade out effect

Hi Warl0ck,

One thing i noticed is that you are using Time.time which is an ever increasing value. So no two executions of this function will be the same. If i were attempting to solve something like this. I would probably use a Coroutine and increment time value manually so when I repeated the effect it would run the same. Something like:

private IEnumerator DoEffect(){
var currentTime = 0f;
var maxTime = 1f;
var height = 0f;
Vector3 pos;
var xScale = 1f;

while(currentTime < maxTime){
height = Mathf.PerlinNoise(currentTime * xScale, 0f);

pos = this.transform.position;
pos.y = height;
this.transform.position = pos;

currentTime += Time.deltaTime;
yield return null;
}

}

Then begin the coroutine whereever its needed. StartCoroutine(DoEffect());

Not sure if that will solve your problem but thought I would point it out in case it helps.

Kind Regards,
Joe

yeah i also thought something like this…

i also saved time instance manually and came up with this solution

public float heightScale = 1.0F;
    public float Speed = 1.0F;
    public bool trigger;
    float i=0;

    void Update() {

        if (trigger) {
            float height = heightScale*Mathf.PerlinNoise (i * Speed, 0.0F);
            Vector3 pos = transform.localPosition;
            pos.y = height;
            transform.localPosition = pos;
            print (i);
            i+=Time.deltaTime;
        }
    }

Every time when trigger will be enable/true it will start shaking with adding delta time in variable (i) and when i stop the trigger it will stop shake and when i will do it continue again it will go smooth and this is all good but still i have no answer for my question

when i will start it for the first time perlin noise will select the random number between 0,1 and lets say my camera is at 0.2 and perlin noise got the 0.8 and smooth graph so in that frame my camera will be jumped to 0.8 from 0.2 and then it will be smoothly shakes up

and that what i have my problem at

i want to stop that jump from camera position to initial perlin noise…i want to control that jump

thats why i am asking for fade in effect tso it will not look like sudden movement of camera transform

i hope you got that what i am trying to ask in this forum…