How Do You Make the Screen Shake?

Blitz3D Forums/Blitz3D Beginners Area/How Do You Make the Screen Shake?

Crazy4Code(Posted 2005) [#1]
Ya know how, in Need For Speed Underground and some other racing games, the screen shakes when you're going fast enough? How do you do that?


Yan(Posted 2005) [#2]
Shake the camera.


sswift(Posted 2005) [#3]
One way would be to do this:

1. Attach camera to a pivot.

2. Move the pivot instead of the camera for normal camera movements.

3. Define two variables, Camera_Offset_X#, Camera_Offset_Y#.
This is the location in pivot space at which the camera should be positioned. These values should be 0 normally.

4. Each frame, move the camera a bit towards the position defined by these two variables, at a constant rate of speed.

5. When camera shake is needed, every X milliseconds, choose a new offset for the camera. The amount of this offset should be proportional to the amount of camera shake. Ie, Camera_Offset_X# = Rnd(0, 1) * ShakeForce#
Camera_Offset_Y# = Rnd(0, 1) * ShakeForce#


Because you are moving the camera towards the desired location at a constant rate every frame, when you change the offset the camera starts moving towards the new offset. You should make sure the camera can move fast enough to get to the offset before you choose the next one.

Also, the number of times per second you change the offset the camera should move towards affects how much vibration there is. The size of the offsets affects how firmly the camera seems held in place.

If you can simulate springs, then putting the camera on a set of springs and then applying a random force to it in a desired direction might work too and be more realistic.


IPete2(Posted 2005) [#4]
Granty3,

Check out QuakeCam in the code archives. Lovely!

IPete2.


Oddball(Posted 2005) [#5]
Grab your monitor firmly with both hands and shake it. This method is easier if you have an lcd display :)

Sorry. I saw the topic and couldn't help myself. I'll get my coat now.


Najdorf(Posted 2005) [#6]
> Grab your monitor firmly with both hands and shake it.

argh, I was beaten in time...


big10p(Posted 2005) [#7]
All I have to do is walk across the bedroom floor - I live in a very old cottage with wonky floors. The whole room shakes just walking on them. :/