Game Development Community

Global camera shake

by David Horn · in Torque Game Engine · 10/14/2008 (3:27 pm) · 3 replies

Is there a way to code the camera shake so that affects all cameras?

here's my problem.

I'm successfully implementing the tracking camera to get a stationary 3rd person view/
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4720

when I add the camera shake to my existing (and working) explosion, it doesn't shake.

my thought is that the camera code is not affecting the correct camera, so my initial solution is to see if I could code a global shake that would affect all cameras in the scene. unless there's a better way.

Any help would be appreciated.

#1
10/14/2008 (4:19 pm)
The way in which the camera shake effect is written means that it only affects the 1st person camera.

You could probably rewrite it to affect 3rd person cameras as well.
#2
10/15/2008 (12:23 pm)
You mean in the code of the explosion.cc file?
#3
10/21/2008 (6:35 am)
Looking into it a little further, it looks like there are 2 places where the camera shake is coded.

the first is inside the explosion.cc which i figured.

// shake camera
   if( mDataBlock->shakeCamera)
   {
      // first check if explosion is near player
      GameConnection* connection = GameConnection::getConnectionToServer();
      ShapeBase *obj = connection->getControlObject();

      bool applyShake = true;

      if( obj )
      {
         ShapeBase* cObj = obj;
         while((cObj = cObj->getControlObject()) != 0)
         {
            if(cObj->useObjsEyePoint())
            {
               applyShake = false;
               break;
            }
         }
      }


      if( applyShake && obj )
      {
         VectorF diff = obj->getPosition() - getPosition();
         F32 dist = diff.len();
         if( dist < mDataBlock->camShakeRadius )
         {
            CameraShake *camShake = new CameraShake;
            camShake->setDuration( mDataBlock->camShakeDuration );
            camShake->setFrequency( mDataBlock->camShakeFreq );

            F32 falloff =  dist / mDataBlock->camShakeRadius;
            falloff = 1.0f + falloff * 10.0f;
            falloff = 1.0f / (falloff * falloff);

            VectorF shakeAmp = mDataBlock->camShakeAmp * falloff;
            camShake->setAmplitude( shakeAmp );
            camShake->setFalloff( mDataBlock->camShakeFalloff );
            camShake->init();
            gCamFXMgr.addFX( camShake );
         }
      }

It looks as though I would first need to automatically set the variable applyShake to true, because in my game, distance does not matter.

Then it calls the function gCamFXMgr.addFX( camShake );
This is located in the cameraFXMgr.cc

I'm assuming that it is inside this file that I would look for the reference to the first-person camera and change that to my tracking camera? I can't see where that might be.

Also, I have the afxCameraShake.cc file, so I'm not sure if that would also have to be modified?