7
\$\begingroup\$

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?

\$\endgroup\$
5

1 Answer 1

8
\$\begingroup\$

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.

enter image description here

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.

enter image description here

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.

enter image description here

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Fantastic visualizations! +1 \$\endgroup\$
    – Gerstmann
    Jan 17, 2013 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .