Hey i leave you one script i made for a camera shake effect that is applied when a big spell explodes, maybe it gives you some ideas. It worked for me really nice you can twitch the timing and it has a linear ease down it starts at the maximum shake power and it decrease by the amount you want.
private var ShakeAmount : float;
private var ShakeDuration : float;
private var TimeShaking : float;
private var DefaultPositionX : float;
private var DefaultPositionY : float;
private var ShakeSlow : float;
function Start () {
DefaultPositionX = transform.localPosition.x;
DefaultPositionY = transform.localPosition.y;
}
function Update () {
if (TimeShaking <= ShakeDuration) {
transform.localPosition.x = Random.Range(-ShakeAmount , ShakeAmount);
transform.localPosition.y = Random.Range(-ShakeAmount /3 , ShakeAmount/3);
TimeShaking += Time.deltaTime;
ShakeAmount -= ShakeSlow;
} else {
transform.localPosition.x = DefaultPositionX;
transform.localPosition.y = DefaultPositionY;
}
}
function ShakeCamera(ExpPower : float, ExpDuration : float){
ShakeAmount = ExpPower;
ShakeDuration = ExpDuration;
TimeShaking = 0.0;
ShakeSlow = ShakeAmount / (ShakeDuration / Time.deltaTime);
}
============== EDIT ==============
Sorry i have to clarify i made this for a 2D game thats why i move the x and y position and not the rotation, but you can adjust that to your convenience. Hope it helps
↧