Plastic Gem #43: Death Orbit Cam
by Anthony Rosenbaum · 08/20/2008 (6:22 am) · 4 comments
Download Code File

Death Orbit Cam
Difficulty: Easy
This gem is short and sweet. If you were to look at the definition of the camera object in camera.h you might notice an enumerator for the various modes the camera can be in
Specifically notice how there is a OrbitPointMode, you might also note that the internal method setOrbitMode() is designed to have the camera orbit around point if an object is not provided. However if you ever tried to use this feature you would find it does not work for some reason. The problem resides in the console method setOrbitMode() which in turn calls the internal setOrbitMode().
There is a check within the console method which will exit the function if an object is not provided
The easiest fix is to comment out this check AND be sure that when you want to orbit around a point that you are ALWAYS providing a position in the camera's setOrbitMode() call from script.
Why would you want to do this? Maybe you want to have the camera orbit above an object like a flag at the end of the game
Or
Maybe you want to have the camera rotate above the enemy that killed you.
Regardless, this fix make the setOrbitMode() more flexible and allows you use that OribitPointMode feature which is already built in. You are not longer restricted to orbit an object's transform, but rather provide a transform you want the camera to orbit around.
The Next Gem
We will look at providing custom FOV for individual weapons.

Death Orbit Cam
Difficulty: Easy
This gem is short and sweet. If you were to look at the definition of the camera object in camera.h you might notice an enumerator for the various modes the camera can be in
enum
{
StationaryMode = 0,
FreeRotateMode = 1,
FlyMode = 2,
OrbitObjectMode = 3,
OrbitPointMode = 4,
CameraFirstMode = 0,
CameraLastMode = 4
};Specifically notice how there is a OrbitPointMode, you might also note that the internal method setOrbitMode() is designed to have the camera orbit around point if an object is not provided. However if you ever tried to use this feature you would find it does not work for some reason. The problem resides in the console method setOrbitMode() which in turn calls the internal setOrbitMode().
There is a check within the console method which will exit the function if an object is not provided
if(Sim::findObject(argv[2],orbitObject) == false)
{
Con::warnf("Cannot orbit non-existing object.");
object->setFlyMode();
return;
}The easiest fix is to comment out this check AND be sure that when you want to orbit around a point that you are ALWAYS providing a position in the camera's setOrbitMode() call from script.
Why would you want to do this? Maybe you want to have the camera orbit above an object like a flag at the end of the game
%flagXform = %Flag.getTransform();
%flagXform = setWord(%flagXform, 2, getWord(%flagXform, 2) + 5 );
%cam.setOrbitMode("", %flagXform, 2.5, 10.5, 7.5, false);Or
Maybe you want to have the camera rotate above the enemy that killed you.
%playerXform = %player.getTransform();
%playerXform = setWord(%playerXform, 2, getWord(%playerXform, 2) + 2 );
%cam.setOrbitMode("", %playerXform, 0.5, 4.5, 3.5, false);Regardless, this fix make the setOrbitMode() more flexible and allows you use that OribitPointMode feature which is already built in. You are not longer restricted to orbit an object's transform, but rather provide a transform you want the camera to orbit around.
The Next Gem
We will look at providing custom FOV for individual weapons.
About the author
#2
Its not that hard to specify "NULL" or "0", as the Object which basically will bypass the check anyways
08/23/2008 (9:24 am)
This fix isn't completely needed.. Its not that hard to specify "NULL" or "0", as the Object which basically will bypass the check anyways
#3
not able to get this to work in TGEA 1.8.1
//i edited this line to return a player transform
%playerXform = %client.player.getTransform();
//what is the function of this line ? it seems to just tack 2 in front of the transform
%playerXform = setWord(%playerXform, 2, getWord(%playerXform, 2) + 2 );
/// this line returns obj not found ...
%cam.setOrbitMode(%client.player, %playerXform, 0.5, 4.5, 3.5, true);
03/29/2009 (10:22 pm)
Bumpnot able to get this to work in TGEA 1.8.1
//i edited this line to return a player transform
%playerXform = %client.player.getTransform();
//what is the function of this line ? it seems to just tack 2 in front of the transform
%playerXform = setWord(%playerXform, 2, getWord(%playerXform, 2) + 2 );
/// this line returns obj not found ...
%cam.setOrbitMode(%client.player, %playerXform, 0.5, 4.5, 3.5, true);
#4
With regards to the second question, you need to get the ID of your camera before you can use %cam. Maybe something like %cam = %client.camera
BTW, if i'm wrong in any aspect, feel free to correct me. One thing I'm wondering though, is there a way to use the camera book marks from within a game/mission. Say, changing the camera position to the book mark position during a scripted event ?
04/28/2009 (8:41 pm)
With regards to the first question, the line gets your player position and ADDS 2 to the Y axis ? This is to used to set the camera position. Change it to what ever position you want. With regards to the second question, you need to get the ID of your camera before you can use %cam. Maybe something like %cam = %client.camera
BTW, if i'm wrong in any aspect, feel free to correct me. One thing I'm wondering though, is there a way to use the camera book marks from within a game/mission. Say, changing the camera position to the book mark position during a scripted event ?

Associate Michael Hall
Distracted...