SFML community forums

Help => Graphics => Topic started by: SFMLNewGuy on January 23, 2020, 04:59:15 pm

Title: Shaking the Camera
Post by: SFMLNewGuy 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.
Title: Re: Shaking the Camera
Post by: AlexAUT on January 24, 2020, 12:32:35 pm
You can try something like this: https://gamedev.stackexchange.com/a/47565
Title: Re: Shaking the Camera
Post by: SFMLNewGuy 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
Title: Re: Shaking the Camera
Post by: Hapax on January 29, 2020, 09:25:51 pm
I once implemented a simple camera shake in my version of the SFML logo animation (https://github.com/Hapaxia/SfmlLogoAnimation), like this:
(click to show/hide)

It ended up looking like this:
https://www.youtube.com/watch?v=vp1TMtuBlcA
Title: Re: Shaking the Camera
Post by: SFMLNewGuy on January 30, 2020, 04:54:30 am
I once implemented a simple camera shake in my version of the SFML logo animation (https://github.com/Hapaxia/SfmlLogoAnimation), like this:
(click to show/hide)

It ended up looking like this:
https://www.youtube.com/watch?v=vp1TMtuBlcA

Wow! That was really cool man. I couldn't get that function to work on my program. So I'll have to look at it deeper, thought I covered all the variables, but I'm not using them right. Thanks for the example.
Title: Re: Shaking the Camera
Post by: Paul on January 31, 2020, 07:34:17 pm
GDC is really good source: https://www.youtube.com/watch?v=tu-Qe66AvtY