### Author Topic: Shaking the Camera  (Read 1585 times)

0 Members and 1 Guest are viewing this topic.

#### SFMLNewGuy

• Jr. Member
• Posts: 65
##### Shaking the Camera
« on: January 23, 2020, 04:59:15 pm »
Hello,

So I was trying to see if I could emulate a camera shake (like when you get hit). I'm not having much success though. Does anyone have a good way to do this?

What I was trying to do is rotating it based on my delta time. Such as:

if(bShake) {
dt+=deltaTime;
if(dt > 0.01)
camera.rotate(90);
if(dt > 0.03)
camera.rotate(-100);
if(dt > 0.06)
camera.rotate(110);
etc....
if(dt>1.f)
shake=false;
(set the camera back to default)
dt=0;
}
and ending back to the normal position.

It doesn't work how I imagined it. It's very slow, I tried messing with the times to make them quicker. I'm looking for a way to do this correctly. A very quick back and forth (rumble) Thanks.

#### AlexAUT

• Sr. Member
• Posts: 396
##### Re: Shaking the Camera
« Reply #1 on: January 24, 2020, 12:32:35 pm »
You can try something like this: https://gamedev.stackexchange.com/a/47565

#### SFMLNewGuy

• Jr. Member
• Posts: 65
##### Re: Shaking the Camera
« Reply #2 on: January 29, 2020, 11:28:13 am »
Hey, thanks! My link to this message ended up in the wrong folder. That's helpful!

Take care

#### Hapax

• Hero Member
• Posts: 3050
• My number of posts is shown in hexadecimal.
##### Re: Shaking the Camera
« Reply #3 on: January 29, 2020, 09:25:51 pm »
I once implemented a simple camera shake in my version of the SFML logo animation, like this:
(click to show/hide)

It ended up looking like this:
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

#### SFMLNewGuy

• Jr. Member
• Posts: 65
##### Re: Shaking the Camera
« Reply #4 on: January 30, 2020, 04:54:30 am »
I once implemented a simple camera shake in my version of the SFML logo animation, like this:
(click to show/hide)

It ended up looking like this: