Game Development Community

Camera bob

by Eric Armstrong · in Torque Game Engine · 11/10/2001 (1:33 pm) · 8 replies

I'm working on a sniper simulation, and one of things I want for the game is for the camera to "bob" up and down when the player is standing still based on how much physical effort the player has exerted in the recent past.

My initial thought on how to accomplish this was to add an onIdle method to the camera similar to the onAdd and onRemove methods currently in the system. The issue at this time is I'm not sure how to get the engine to call that new function when the player is standing still. I'm guessing I'll need to pass something through the event system, but I'm not sure. Has anyone else attempted something similar and can point me in the right direction? Does this sound like the best way to accomplish my objective? If I can just get the camera to "bob" any amount when the player is standing still, I shouldn't have a problem hooking the rate and amount of the "bob" to the player's recent activity.

Basically what I'm trying to accomplish is that if the player just ran a mile at a full sprint and then tries to line up a 400 yard shot, they will have to contend with the increased rate of breathing from the run. This is what the camera bob is there to simulate. Any help anyone can give me would be appreciated.

Thanks,
Eric

#1
11/10/2001 (2:09 pm)
Right after posting the above, I took another look at the code and may have found a better way to do this. I noticed that in the player.cc file there is a section of code commented as "shake camera on ground impact". It accesses a class called CameraShake and an object gCamFXMgr. This is located in the updatePos method of the player class. What I was thinking of doing now, was to set up a camera effect similar to CameraShake that handles the actuall bobbing of the camera. I will then set up that class and add it to the gCamFXMgr object. I'm looking at doing this from within the updateActionThread. I'm simply adding an if statement checking if the current mActionAnimation.action is equal to RootAnim in the PlayerData enum. I'll let everyone know how it goes. In the meantime, if anyone sees any problems with the above, let me know.

Thanks,
Eric
#2
11/10/2001 (3:00 pm)
Sound interesting, please post any updates on this subject.

Thx.

// Clocks out

www.flashthunder.com
#3
11/12/2001 (8:28 am)
Well I'm making progress. Not a whole lot of progress, but progress none the less. I have my camera FX class set up, and I modified player.cc to add a single instance of the effect to the effect manager when the player goes into the root animation. Right now the only problem is the effect doesn't work! I'll give an explanation of what I'm doing in the hopes that someone here can point out my stupid mistake. Basically what I'm doing is incrementing or decrementing a class variable by some amount. I then assign that amount to the z coordinate. I do no rotation and then set the mCameraFXTrans (I think thats the variable) to the new position. In pseudocode it goes something like this:

if up
   mSetting += 0.001;
else
   mSetting -= 0.001;

pos.z = mSetting;

if pos.z > 1 or pos.z < 0
 up = !up
rot.x = 0
rot.y = 0
rot.z = 0

trans = euler (rot)
trans.pos = pos
cameraFXTrans = trans;

The thing I'm most unclear about is the amount to move the camera by each time, and the ceiling and floor to set in the if statement. What exactly is the unit of measurement set at? Is 0.001 way too small, or way to large? My instinct tells my I should be using the mElapsedTime member to adjust amounts and smooth the camera bobbing. What's ending up happening when I run the app is all the terrain, buildings, and models disappear then reappear, like a flashing. It gives me the feeling that the camera is suddenly shooting way way up in the sky then immediately flashing back down to the ground. I have experimented with various different numbers, all to no effect. There is probably some sort of algorithm that will solve all this for me I just don't know it.

Anyone have any ideas? If you want, I can post the exact code when I get home.

Thanks for any help
Eric
#4
11/19/2001 (4:11 pm)
I finally figured it all out. Thanks go out to Mark Barry for throwing some code my way that, even though it was just using the existing camera effect, snapped something in my head and got me on my way. Thanks a bunch Mark!!

I'm going to do some tests with various amounts of bobbing and clean up some hacks I threw in to get things up and running, then it's just a matter of tying some variables within the player class to the values passed to the effect. Once everything is in place and functioning properly, I can put together an explanation of what I did and how it works if anyone would be interested. Let me know.

Eric
#5
11/20/2001 (1:59 am)
Yup, im still interested ;P

Sounds great.

// Clocks out

www.flashthunder.com
#6
11/20/2001 (8:04 am)
Eric, I'm glad I could help. I'm still trying to perfect the camera bob but it's a good start.

Mark
#7
06/13/2003 (12:27 pm)
hey any else got this working?
#8
06/13/2003 (12:35 pm)
Me too.