Screen Shake c#

Hello,

I’m trying to make my entire camera (or screen) shake when an explosion is triggered for example. I have no idea how to go about doing this. Currently I just have a cube GameObject on screen for test purposes, but not sure exactly how to continue with this.

Any help would be amazing,

EDIT: I am using iTween atm.

Thanks.

You have a tweener? If you don’t get some tweener library.

Now, a nice shake would just be moving the camera’s position left and right, up and down a little… back and forth. So generate a bunch of points to the left and right, up and down of your camera’s stable position.

Tween through all those points.

Maybe also include a little swaying of the left right rotation.

I’m a total noob to Unity, just started using it like the other day. s;

public class Test : MonoBehaviour {

Hashtable ht = new Hashtable();

void Awake()
{
ht.Add(“x”,3);
ht.Add(“time”,4);
ht.Add(“delay”,1);
ht.Add(“onupdate”,“myUpdateFunction”);
ht.Add(“looptype”,iTween.LoopType.pingPong);

}
void Start () { iTween.ShakePosition(gameObject, ht); }

}

This is what I currently have, and I have the script on the MainCamera, is that a correct way to do it?

correct?

You have code written, run it. Does it do what you want it to do? If so, yes, it’s correct.

If not, explain what didn’t happen correctly, and maybe we can help you. You’re a self proclaimed newb though, so start digging in it yourself and see what happens… you can learn a lot from trial and error.

Yeah it ended up working, just took me a while to realize I had to actually put it on my camera. Didn’t understand why the two weren’t linking up. But I got it, and made it so on input it will shake, and not loop. Thanks!