# Swaying Camera when Walking

You can see the effect in many games. The camera sways or wiggles a bit while walking to make the movement feel more realistic.

I have implemented a camera in my game. (Who'd have thunk it?) So is there a common approach to build this swaying effect in?

-
It's usually just a sinewave, take a look at this: stackoverflow.com/questions/6077652/swinging-bobbing-camera – bryan226 Dec 24 '12 at 11:19
An alternative would be parenting a camera to a rigged characters head resp. eye bone. The movement of the camera will then follow the movement of the character. Ofc, just using sine waves is easier to implement and compute. – sarahm Jan 10 '13 at 23:58
@sarahm. Since there are no character animations implemented in my game yet, I can't do that now. But I would like to implement that some day. – danijar Jan 11 '13 at 10:12
– Byte56 Jan 14 '13 at 19:52
possible duplicate of How can I implement view wobble when my player is running? – Byte56 Jan 14 '13 at 19:52

Applying a transformation to the world from the point of view of the camera is the most straight forward way.

When the character advances the camera can be modeled as a cartwheel without the wooden circle, keeping just the wooden sticks. This curve is called cycloid.

Also with each foot step the camera needs to move slightly to one side or the other as if the wooden sticks where separated by the horizontal distance between the two legs, balancing the center of mass to keep it vertically aligned with the foot touching the ground.

The two movement seen from the point of view of the camera would look like half a circle (or an ellipse).

Approximating the cycloid to a sinusoidal, the translation would be given by:

translation( A * cos(d + pi/2), B * sin(pi/2 - 2*d), 0 )

Where d is the distance since the character started to move. The movement speed can be modified by multiplying d by a factor, or the values of X or Y by an arbitrary amplitude.

-
Fantastic visualizations! +1 – Gerstmann Jan 17 '13 at 11:19