This topic is now archived and is closed to further replies.


Shaking Screen Question

Recommended Posts

Hi, I want to make a shaking effect on the screen.I used an array of (x,y) to record the shaking offsets.Such as (-4,0),(0,0),(4,0),(0,0),(0,-4),(0,0),(0,4).And when shaking screen,I take out the offset from this array one by one ,and apply them to the screen coordinate.What troubles me is it''s so difficult to define these shaking points to make a realistic shaking effect.Any one has good suggestion?

Share this post

Link to post
Share on other sites
Here's one way, define variables to hold the look at point for your scene camera. Now, make a function that generates random numbers between -ve and +ve of whatever maximum amount you want your screen to shake by.

Multiple this by a variable like blastFactor, which is determined by the element that causes the screen to shake - like an explosion - and varies with the intensity of the explosion between 0.0f and 1.0f. Multiply this value with the random number and add it to your camera's look at point and Voila! you have a varying explosion that doesn't look the same every time.

Something like this :-

Vector3 m_vLookAtPt = Camera->GetLookAtPt();

float fShakeAmtX = Rand( 5 );
float fShakeAmtY = Rand( 7 );

Determine you blast intensity and hold it in blastFactor.

m_vLookAtPt.x += fShakeAmt * blastFactor;
m_vLookAtPt.y += fShakeAmt * blastFactor;

Camera->SetLookAtPt( m_vLookAtPt );

Now, make a function with this and put a loop to decrease the Rand value by, say 1, every time...

and subtract the shake amount term from the LookAtPt vector.

for( int i = 5; i >= 0; --i )
float fShakeAmtX = Rand(i);

Now, the screen shake will gradually decrease to zero.

Hope that was kinda clear...

[edited by - poly-gone on September 4, 2003 8:28:32 AM]

[edited by - poly-gone on September 4, 2003 8:30:43 AM]

Share this post

Link to post
Share on other sites
Original post by PhilVaz
<< I want to make a shaking effect on the screen. >>

Here is another way to do it....

Shake Me I like it
Phil P

That was really unnecessary.

For anyone who is thinking of clicking that link... its a shaking window it doesn't open a new window and you cant hit the back button.

[edited by - Biomass Negative on September 5, 2003 1:47:08 AM]

Share this post

Link to post
Share on other sites
<< you, sir, are a scumbag. >>

Then absolutely, under no circumstances, do not click on this link either


Or you could see it as a game and try to escape browser hell....just something I learned from the GameDev folks, but I made it worse.

Phil P

[edited by - PhilVaz on September 5, 2003 9:53:48 PM]

Share this post

Link to post
Share on other sites