shake camera

hey guys, im looking for a cool effect to shake the camera, the method i tried completly molests it rather than shakes :smile:.

heres the script below (its called from another script).

var speed = 10;
var cam = Transform;

var WaitTime : float = 0.5;

function Update () {
if(GameBoy.Shaking) {
Shake ();
	}
}

function Shake () {
	transform.Translate(0,speed,0);
	yield WaitForSeconds (WaitTime);
	speed = -10;
}

the idea is to emulate the shake by making it move up slightly then down, vice versa. But i think this interfears with the script to make the camera follow the player. So anyone got any ideas that might work? thanks!

I’m using this simple method to “shake” camera in one axis - adjust random multiplier (anyway, it’s better to use x*0.25 instead of x/25). You can add Your Yield between random position and returning to base position. Hope it helps in some way :wink:

private var basePosition : Transform;

function Awake () {
	basePosition = gameObject.transform;
}

function FixedUpdate () {
	transform.position.x = Random.value/10;
	gameObject.transform.position = basePosition.position;
}

Edit: if You want Your camera to move after “something” and shake, use:

transform.position.x = transform.position.x + Random.value/10;

great tjhanks alot! ill give a test tommorow :smile: