Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shaking the Camera  (Read 3250 times)

0 Members and 1 Guest are viewing this topic.

SFMLNewGuy

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
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
    • View Profile
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
    • View Profile
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: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
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
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

SFMLNewGuy

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
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:


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.

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: Shaking the Camera
« Reply #5 on: January 31, 2020, 07:34:17 pm »
GDC is really good source: