Skip to main content
gamedev.net
🔒 Locked

Camera Shake Help

Started by victoryismine06 Mar 11, 2009 at 3:21 PM 7 replies 4.6k views
Original Post
victoryismine06
victoryismine06
Hey all, Ok so I'm trying to add a camera shake method to my camera class and I'm having a few problems. First off I'm using Directx 9.0c and its basically a 2D Side Scroller so I want the camera to shake when a bomb or explosion happens within a certain distance from the player. So does anyone have an algorithm or any suggestions on how to correctly "shake" the camera? Anyone? Thanks!
zedz
zedz
just move the camera from side to side, press smartbomb in my latest demo (see journal)

use_mv_mat.a03 += sin( shake_horizontal_speed ) * shake_horizontal_magnitude;
shake_horizontal_magnitude *= shake_dampening_amount;
clivehk
clivehk
simple harmonic motion (SHM)
zedz has shown a SHM of shearing

u could also try rotation about the local z-axis (not world axis)

cam.rotz = D3DX_PI/18;

while(shaking)
{
if(cam.rotz > 0)
rotspeed.z -= rate;

else
rotspeed.z += rate;
}


cam.zrot += rotspeed.z;
eq
eq
I advice against moving the camera since this could move the camera through objects (walls etc) unless you also add a collision avoidance step.
It's better IMO to rotate the camera.

Zakwayda
Zakwayda
Quote:
Original post by eq
I advice against moving the camera since this could move the camera through objects (walls etc) unless you also add a collision avoidance step.
It's better IMO to rotate the camera.
It sounds to me like it's a 2-d game (side-scroller), in which case camera-obstacle interference isn't likely to be an issue.
victoryismine06
victoryismine06
Yea there is no worry about the camera having any collision issues. I'll try moving it back and forth like you suggested. I guess I'm still a little confused on how it works. Won't it have to do something like this:

Move Camera
Render Scence
Move Camera
Render Scene
Move Camera
Render Scene

Do I just do this for a certain amount of specified time or until the DeltaMove is equal to zero? Thanks!
clivehk
clivehk
Quote:

Yea there is no worry about the camera having any collision issues. I'll try moving it back and forth like you suggested. I guess I'm still a little confused on how it works. Won't it have to do something like this:

Move Camera
Render Scence
Move Camera
Render Scene
Move Camera
Render Scene


nah, assuming u are using win32 application,
u should hv a main message loop, where u update and render everything
its a bad habit to update and render things one by one IMO

// main msg loop
while(...)
{
everything.update();

device->beginScene(...);
everything.render();
device->...
...
}

Quote:

Do I just do this for a certain amount of specified time or until the DeltaMove is equal to zero? Thanks!


its all up to u
if u are going to use zedz's equations,

if(shake_horizontal_magnitude <= "a certain amount")
{
shake_horizontal_magnitude = 0;
SHAKING = false;
}

zedz
zedz
cheers for the rotation on the z axis idea (I didnt think of that)
though I've just now tried it + personally it doesnt look as good as side to side

shaking shouldnt affect clipping into the scenery as if clipping is an issue u should already be handling it.

>>if(shake_horizontal_magnitude <= "a certain amount")
...
...

I wouldnt even worry about if the camera is shaking or not, I apply shaking to the camera every frame, i.e. even if visually 99.99% u dont see it.
KISS
victoryismine06
victoryismine06
Quote:
Original post by clivehk
nah, assuming u are using win32 application,
u should hv a main message loop, where u update and render everything
its a bad habit to update and render things one by one IMO

// main msg loop
while(...)
{
everything.update();

device->beginScene(...);
everything.render();
device->...
...
}


Ok, I think I have it setup somewhat correctly. I have my "everything" class and a music class in my main message loop. Then in my "everything" class I call the rest of my objects so I think I'm good there. I'll try to implement the camera class like u suggested and see what happens. Thanks for the help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.