Game Development Community

Camera.setTransform() odd behavior (fixed)

by Maxime Jouin · in Torque Game Engine · 10/05/2007 (6:36 am) · 7 replies

Hello,

I am having problems with moving the camera. I am using the stock TGE 1.5.2 cam, with no modifications. By default, I have a third person view with my cam following the player. When the user interacts with an NPC, I move the camera to show the face of the NPC in question. To do this, I first calculate the desired position of the cam tby getting the eye transform pf the NPC through the C++ player method getEyeTransform. I then change the Z position to Z=Z-0.2; so that the cam moves back from the NPC. Then, through script, I send the matrix to the server using:

commandToServer ('MoveCameraToNPCPosition', %myMatrix);

Where %myMatrix contains: "XPos YPos ZPos XRot YRot ZRot AngAxisF". Then, server side, I have this following code:
function serverCmdMoveCameraToNPCPosition(%client, %myMatrix )
{
   %ang = getWord(%myMatrix , 6);
   %ang = mDegToRad (mRadToDeg (%ang) + 180);
   %client.camera.setTransform(%myMatrix);
   %client.setControlObject (%client.camera);
}
Then, when interaction with the NPC is done, the camera is restored to normal third person view by issuing a server commad. The server side code is:
function serverCmdMoveCameraToPlayerPosition (%client)
{
   %client.setControlObject( %client.player );
}
THIS WORKS PERFECTLY! The problem lies elsewhere.

I also give the user a possibility to switch to orbit mode. The server side code allowing to toggle orbitmode on/off is:
function serverCmdToggleOrbitMode(%client, %orbit_mode)
{
   if( %orbit_mode )
   {
      %client.setCameraObject( %client.camera );
      %client.setControlObject( %client.camera );
      %client.camera.setOrbitMode( %client.player, %client.player.getTransform(), 3, 5.8, 5.7, false );
   }
   else
   {
      %client.camera.setFlyMode();
      %client.setCameraObject( %client.player );
      %client.setControlObject( %client.player );
   }
}

THIS ALSO WORKS PERFECTLY!

Now for the problem: whenever I go into orbit mode, then back into third person mode again, the NPC cam doesn't work anymore! It keeps placing the camera at the back of the controlled player. The weird thing is, that the position matrix is exactly the same as before.

I've been trying to figure this out for 2 days and I can't seem to find the problem.

Please help!

#1
10/05/2007 (7:17 am)
So your saying that when you are in NPC mode, looking at the NPC and you enter orbit mode that when you exit back out you are no longer looking at the NPC?

Could it be this line?
else
   {
      %client.camera.setFlyMode();
      %client.setCameraObject( %client.player );
      [b]%client.setControlObject( %client.player );[/b]
   }

In your case shouldnt the control object be kept the camera as indicated by:
function serverCmdMoveCameraToNPCPosition(%client, %myMatrix )
{
   %ang = getWord(%myMatrix , 6);
   %ang = mDegToRad (mRadToDeg (%ang) + 180);
   %client.camera.setTransform(%myMatrix);
   [b]%client.setControlObject (%client.camera);[/b]
}

If this is your problem then you need to keep track on the server if you are viewing an NPC or not and if so then set the control object back to the camera instead of the player.
#2
10/05/2007 (7:36 am)
Hi Brian,

Thanks for your reply but it is indeed the control of the player that I want to restore when I go out of orbit mode. Orbit mode is only accessible to the controlled player when NOT in interaction with an NPC, maybe I forgot to mention that.

So when I go into orbit mode, I control the camera rotation around the player with the movement keys. When I come out of orbit mode, I control the player again with the movement keys. So it is indeed the player that has to be the control object when going out of Orbit Mode.

I tested your suggestion anyway, and it breaks the normale behavior of ToggleOrbitMode as expected. When I go out of orbit mode, the camera is stuck behind the player, and I can't move anything anymore...

A bit more information maybe on how the problem occurs:
- Play normally in 3rd person.
- Interact with NPC, camera moves OK.
- Stop interacting, camera moves back to 3rd person OK.
(repeat as many times as needed, everything works fine...)
- Go into orbit mode, camera turns around the player OK.
- Go out of orbit mode, camera moves back to 3rd person OK.
- Interact with NPC, camera is not OK, it is placed at the back of the player.
- Stop interacting, camera mpves back to 3rd person OK.
(Same behavior occurs every time the player interacts with NPC. Only solution is to restart the game)
#3
10/09/2007 (1:14 am)
I don't mean to rant, but this is the second time I have a MAJOR functionnality problem, to which I get no help. I even sent out a support request email to which I got no answer... again. Please, somebody, anybody! I wouldn't be posting if I could figure this out for myself... If you're wondering, you can check out my other yet unsolved problem. ANy kind of help would really be greatly appreciated.
#4
10/09/2007 (2:20 am)
I know this doesn't help you but I've had the same problem. Heres how I figure it breaks down..

problems solution found
%40 on GG website (resource, forum or TDN)
%40 own solution
%20 still unsolved

However, to be fair, thats why this is a product for *developers* and not average Joes. I never saw any promises of a bug free engine. Only 'an engine with features' which it is.

Might I suggested debugging this issue (and your other one) further and posting the results.

For example:

When your camera breaks, what is the object that the server and client both recognize as the control and camera objects? How does the camera get it's target and who does it think it is?

The only good way to get all of this information is with a debugger, breakpoints and a data inspector (all happily built into Visual Studio).

It sounds to me like Orbit mode is broken somehow. Personally I opted to write my own camera because the one that comes with the engine kinda stinks. Unless your strictly making an FPS which I am not. I would spend some time really examining how it works.
#5
10/09/2007 (2:31 am)
I know this is a "product for developers" but it does not come free of charge either. I mean if this were a free open source product, it could be understandable, but selling a product and not stepping up to correct its problems is another thing entirely... And selling a 3D engine with a faulty camera, is even worse!

I'm sorry if I come out rude or uncivilised, but the more I use Torque, the less I'm convinced it does what it claims... Sorry.
#6
10/09/2007 (7:20 am)
I really don't have a problem with what your saying or why. I don't work for GG or anything like that but I'm curious if you could provide a link to a claim that isn't fulfilled.

Besides that, I'm also curious to know where you're going to get another engine for even ten times the price that does half as much.

And besides that... Try doing everything you want automatically in any other engine. It ain't gonna happen unless you want exactly what that engine developer wanted (and then whats the point???).


Edit*

Oh, and you certainly don't sound rude or uncivilized. I just feel your concerns are unfounded. If you wanted full tech support try licensing the Unreal engine or the Quake engine (of course you're gonna pay about $250,000 but thats a moot point right?). Of course they're not gonna code your camera either...

Heck, try a commercial Torque license, I bet you get better response.
#7
10/11/2007 (6:48 am)
I finally fixed the problem by removing the calls to setCameraObject in the toggleOrbitMode server function.

I don't know why this works, and why it caused the bug, and I'd appreciate it if someone could actually explain it to me.

Thanks! And sorry for the ranting, this thing really had me in a bad mood...