Game Development Community

Advanced Camera in T3D

by Stephen · in Torque 3D Professional · 07/30/2013 (12:53 pm) · 15 replies

I have spent countless hours trying to figure out how to get this thing working. I have browsed the forums trying to find a solution and haven't found out. I have got the engine to rebuild with no errors but when I join the game the advanced camera isn't working. I get these errors in the console.
scripts/server/gameCore.cs (230): Unable to find object: '' attempting to call function 'setPlayerObject'
scripts/server/gameCore.cs (231): Unable to find object: '' attempting to call function 'setThirdPersonMode'
scripts/server/gameCore.cs (232): Unable to find object: '' attempting to call function 'setFollowTerrainMode'
scripts/server/gameCore.cs (233): Unable to find object: '' attempting to call function 'setVerticalFreedomMode'

I have moved the functions around in the script to see if that works and nothing seems to work. Now I've had to change a few things in the source to get it to compile with no errors. The only thing I can think of is that the ConsoleMethods are not in the right spot or to out dated to work. Here's the cpp and h files, see if you can find anything wrong.

Link to files

Besides the ConsoleMethods, the only other thing I can see is different is,
if (bstream->readFlag())   
      {  
         S32 gIndex = bstream->readInt(NetConnection::GhostIdBitSize);  
         ShapeBase* obj = [bold]static_cast[/bold]<ShapeBase*>(resolveGhost(gIndex));  
         setCameraObject(obj);  
         obj->readPacketData(this, bstream);  
      }  
      else  
         setCameraObject(0);

if (bstream->readFlag())
      {
         S32 gIndex = bstream->readInt(NetConnection::GhostIdBitSize);
         GameBase* obj = [bold]dynamic_cast[/bold]<GameBase*>(resolveGhost(gIndex));
         setCameraObject(obj);
         obj->readPacketData(this, bstream);
      }
      else
         setCameraObject(0);

#1
07/30/2013 (5:03 pm)
not quite sure what your trying to do here?

are you trying to add the old TGEA Advanced Camera resource to T3D MIT?
#2
07/30/2013 (5:08 pm)
I'm just trying to add the resource. I'm not a programmer, I'm not sure what to do.
#3
07/30/2013 (11:00 pm)
Search your console.log for 'non-conobject' (without the quotes) - it may be that the camera isn't being registered in the console correctly. What goes wrong - what do you see when you start a level?
#4
07/30/2013 (11:18 pm)
So I started with a fresh build of the Full template using the Project Manager. I applied the changes to the scripts and still nothing. Here's the Console Log. I enter the game in first person view.
#5
07/30/2013 (11:27 pm)
Well it seems clear that whatever the reason, your advanced camera object is not actually being created, hence all the warnings about the empty string (new returns this if the object fails to be created). But without any errors describing what went wrong it'll be hard to see. I'm not familiar with the advanced camera code, so I can't recommend anything; if nobody else knows what's wrong I might merge the code myself and see if I can debug it.
#6
07/30/2013 (11:29 pm)
I linked the files so anyone can try it out themselves because I'm not a programmer and I need all the help I can get. I would appreciate any help.
#7
07/30/2013 (11:33 pm)
Here's a image of Visual C++ 2010 Express.
imageshack.us/a/img802/3128/uhic.th.jpg
#8
07/31/2013 (12:24 am)
Mind copying the script where you're creating it?
#9
07/31/2013 (12:34 am)
Placed,
// create advanced camera  
      %this.advCamera = new AdvancedCamera() {  
      dataBlock = AdvCameraData;  
   };  
   MissionCleanup.add(%this.advCamera);  
   %this.advCamera.scopeToClient(%this);
In DeathMatchGame::onClientEnterGame.

Placed,
datablock AdvancedCameraData(AdvCameraData)  
{  
   lookAtOffset = "0 0 2";  
   thirdPersonOffset = "0 -3 3";  
   godViewOffset = "0 -20 20";  
   maxTerrainDiff = 2;  
   orbitMinMaxZoom = "5 100";  
   orbitMinMaxDeclination = "10 80";  
   damping = 0.25;  
  
};
In camera.cs

Then placed
// We set the camera system to run in 3rd person mode around the %player  
  %this.advCamera.setPlayerObject(%player);  
  %this.advCamera.setThirdPersonMode();  
  %this.advCamera.setFollowTerrainMode(false);  
  %this.advCamera.setVerticalFreedomMode(false);  
  %this.setCameraObject(%this.advCamera);
In GameCore::preparePlayer. Not sure where to place this one. I know I missed a few other things but those are to clean up the camera when the player leaves game and dies.
#10
07/31/2013 (1:26 am)
In:
function DeathMatchGame::onClientEnterGame(%game, %client)
?
If so, replace %this with %game. (edit: Or %game with %this for the method def.)

It's customary in script (but not mandatory) to label the first variable of a method of a class %this, since it's sending the datablock/object/(class or classname, I forget which) as that first parameter.

In the case of gamecore and gameDM, seems at some point someone decided to go a different route with their naming conventions for the newer version.
#11
07/31/2013 (9:10 am)
I have changed those and still nothing.
#12
07/31/2013 (3:07 pm)
I download the files from the link that Michael posted. When I first tried to compile the engine an error popped up saying something about this function.
bool AdvancedCamera::onNewDataBlock(GameBaseData* dptr, bool reload) {
	mDataBlock = dynamic_cast<AdvancedCameraData*>(dptr);
	//if (!mDataBlock || !Parent::onNewDataBlock(dptr))
	if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
		return false;

	scriptOnNewDataBlock();
	return true;
}
It didn't have the "reload". So I added it and in the .h file I added in public.
virtual bool onNewDataBlock( GameBaseData *dptr, bool reload );

Once I made those changes the engine would rebuild with no problems. After adding the script changes as well when I enter the game I'm in first person view and those errors in the console show up.
#13
07/31/2013 (3:57 pm)
So I restarted with those files that Michael posted. Added them to the project and rebuild. I get these errors,
Error	28	error C2660: 'ShapeBase::onNewDataBlock' : function does not take 1 arguments	F:\Torque\Torque3D\Engine\source\T3D\advancedCamera.cpp	187
	72	IntelliSense: too few arguments in function call	f:\torque\torque3d\engine\source\t3d\advancedcamera.cpp	187
So I searched for other
if (!mDataBlock || !Parent::onNewDataBlock(dptr))
. There are none but I found others that had reload. So I changed the advancedcamera.cpp to match.
bool AdvancedCamera::onNewDataBlock(GameBaseData* dptr, bool reload) {
//bool AdvancedCamera::onNewDataBlock(GameBaseData* dptr) {
	mDataBlock = dynamic_cast<AdvancedCameraData*>(dptr);
	//if (!mDataBlock || !Parent::onNewDataBlock(dptr))
	if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
		return false;

	scriptOnNewDataBlock();
	return true;
}
Then in advancedcamera.h I changed,
bool onNewDataBlock(GameBaseData* dptr);
to
bool onNewDataBlock( GameBaseData *dptr, bool reload );
Then I rebuild the dll and it rebuilds fine. Here's a link to my gameCore.cs. I enter the game and I get those script errors.
#14
07/31/2013 (8:29 pm)
Okay, I have finally figured out what the problem was. I came across this thread about porting the advanced camera TGEA 1.8.1. So I compared and noticed that some of the #includes wasn't there in my files. So I added the missing #includes and it worked like a charm.
#15
07/31/2013 (10:11 pm)
So I ran into a problem when mounting vehicles with the client. The client stays in the position where they mounted the vehicle. I searched the forums and I found that "Tom" posted a fix but I need help getting it working.

www.garagegames.com/community/resources/view/5474/2#comment-62590