Game Development Community

player independent camera

by Roger D Vargas · in Torque 3D Beginner · 06/27/2014 (10:39 am) · 9 replies

I have followed the RTS tutorial to implement an almost isometric like camera, but I want to detach it from the player. The camera must be able to move away from player position and rotate around the lookAt point. After studying the docs, I think that setOrbitObject could be a solution, if I figure out how to place an invisible object on the scene that can be moved and rotated. The other solution is to manually update camera setting the lookAt point, and calculating the correct position of the camera based on the rotation angle.
the problem is that I have no idea about how to implement none of the solutions. Any suggestions?

#1
06/27/2014 (11:05 am)
Look in the code to see how the editor's top down and isometic modes work and then create a new camera mode from that.
#2
06/27/2014 (12:01 pm)
The editor uses freelook: WASD moves camera left/forward/back/right, mouse pressed moves point of view in any direction. What I need is WASD scroll "up/left/down/right" according to the camera rotation (for example, if you have rotated the camera, what the player perceives as "up" could be a vector pointing to some direction between X and Y axis), rotate around the target view by pressing the middle button and zoom in/out with mouse wheel. Wasteland 2 is a good example of what I want to achieve (or Age of Decadence, for a Torque made example)
#3
06/27/2014 (1:04 pm)
The editor has 8 view modes beyond the standard variations of freelook, fly, track and orbit. Camera -> View -> mode. Look at how these modes work and creating a new one that does what you want in the same manner.
#4
06/27/2014 (2:48 pm)
function serverCmdoverheadCam(%client)
{
   %client.camera.position = VectorAdd(%client.player.position, "0 0 30");
   %client.camera.lookAt(%client.player.position);
   %client.camera.controlMode = "Overhead"; 
}

Overhead mode stays at the same height and can be rotated with the mouse, wasd moves on a horizontal plane at current z, e moves up and c moves down - stock RTS Prototype (sort of like you'd want in an RTS).
#5
07/08/2014 (7:01 am)
Keyboard works perfectly, but mouse doesnt rotates. Also, how can I reassign e/c behavior to mouse wheel?
A small suggestion: "0 0 30" produces a top-down view, "30 0 30" produces a more isometric like view.
#6
07/08/2014 (7:21 am)
Mouse won't rotate the camera as long as the cursor is active, and cursor is not usable if the mouse is controlling the camera.
function toggleMouseLook(%val)
{
   if(%val)
   {
      if(Canvas.isCursorOn())
         hideCursor();
      else
         showCursor();
   }
}
Not sure how you would find a way to control both the camera and the cursor with the same device at the same time that would be useful....
#7
07/08/2014 (8:15 am)
Hmm, the only idea I have is to use keys instead of mouse to rotate view or implementing mouse rotation via scripts.
#8
07/08/2014 (9:39 am)
Quote:Also, how can I reassign e/c behavior to mouse wheel?

From the RTS Prototype:
function serverCmdadjustCamera(%client, %adjustment)
{
   if(%client.camera.controlMode $= "OrbitObject")
   {
      if(%adjustment == 1)
         %n = %client.camera.camDist + 0.5;
      else
         %n = %client.camera.camDist - 0.5;
      
      if(%n < 0.5)
         %n = 0.5;
         
      if(%n > 15)
         %n = 15.0;
         
      %client.camera.setOrbitObject(%client.player, %client.camera.getRotation(), 
        0, %n, %n);
      %client.camera.camDist = %n;
   }
   if(%client.camera.controlMode $= "Overhead")
   {
      %client.camera.position = VectorAdd(%client.camera.position, "0 0 " @ %adjustment);
   }
}

function mouseZoom(%val)
{
   // swap the -1 and the 1 in the parameters below to change 
   // which way is in/out
   if(%val > 0)
   {
      commandToServer('adjustCamera', -1);
   }
   else
   {
      commandToServer('adjustCamera', 1);
   }
}

// --- This is where it's bound to the mouse wheel
moveMap.bind(mouse, "zaxis", mouseZoom);
#9
07/08/2014 (1:04 pm)
Sorry - serverCmdadjustCamera() goes in scripts/server/commands.cs and the rest could probably go in scripts/client/default.bind.cs.