- Home /
Image Jumpscare in Front of Camera
Hello, I'm trying to make one of those cheap, really loud jumpscares where an image on a plane would be placed in front of the player camera, as a child, and wait for a certain amount of time, and the jumpscare would pop up again.
I've gotten everything down, but I'm wondering how I would achieve this effect at 0:30 (WARNING! IT IS A JUMPSCARE!)
where the image shakes frantically across the screen like so. Maybe a random offset float of some kind? Any help would be greatly appreciated! :)
Yeah, a simple Coroutine that changes teh position of the image by a few pixels every few frames.
Thank you Cherno for confir$$anonymous$$g this with me! :)
Answer by Basen · Jul 22, 2015 at 09:19 AM
IEnumerator Shake() {
float elapsed = 0.0f;
Vector3 originalCamPos = Camera.main.transform.position;
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;
x *= magnitude * damper;
y *= magnitude * damper;
Camera.main.transform.position = new Vector3(x, y, originalCamPos.z);
yield return null;
}
Camera.main.transform.position = originalCamPos;
}
This is the CameraShake Coroutine I use. Modify the damper and x and y floats for best results! GL and post your result as a video!
Hello Basen, thank you for being kind enough to share your CameraShake Coroutine. I'm getting one small error though when I try to use it: "The name `duration' does not exist in the current context"
Hey yeah sorry, duration is just a float you need to add. Its for how long the shake should persist.
So just
float duration = 0.5f;
for example
Oh, alright then. Just wanted to make sure it wasn't an extra part of your script. Thank you for your support Basen! ;)
Your answer