# How can I implement view wobble when my player is running?

I'm creating a FPS in XNA. So far its' going great. What I'm looking at doing is replicating the camera movements that you see in Modern Warfare. So, if you are walking the camera stays pretty still except for the slight weapon movement, but if you sprint then it shakes left and right. Here is a good example : Modern Warfare 2 camera motion

Has anyone achieved this? If so, can anyone give any pointers or articles that I can take a look at?

## 1 Answer

To implement this technique you'd just want to adjust the view slightly every frame by some smooth factor, typically along axes that lie within the plane of the viewport.

In other words, you want to adjust your camera position upwards and rightwards by some small periodic factor whenever the player is moving. The sine and/or cosine functions can work well for this; you could just:

• At the start of a frame, if the player is still, set a "run time" variable to 0.
• Otherwise if the player is moving, increment the run time.
• Once your view position is computed, offset it to the left by (say) sin(run time) and upwards by (say) cos(run time).

You will probably want to play around with how you increment the run time, and how to damp the resulting offsets so that the effect is quite subtle, otherwise you may disorient or nauseate your players.

You can also combine this with a similar effect applied to whatever gun or implement the player is holding -- this is best done with a specific animation for that object, however. You can see in the Battlefield videos that the guns precess far more than the actual view does. This disconnect in the magnitude of the relative motion helps make the illusion feel more grounded and gives it some depth (much like parallax motion) which can make it look less fake.