Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
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
1  
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
1  
See here gamedev.stackexchange.com/questions/24850/… –  Byte56 Jan 14 '13 at 19:52
1  
possible duplicate of How can I implement view wobble when my player is running? –  Byte56 Jan 14 '13 at 19:52
add comment

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
1  
Fantastic visualizations! +1 –  Gerstmann Jan 17 '13 at 11:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.