Introduction

The Torque 3D Camera object has several modes and member fields to adjust the control to desired game play. Additionally, the Torque 3D Camera object has been changed from previous versions of Torque. Major changes include

  • Smoothing effects apply to all modes
  • Two new modes are included
  • Game play and editor specific cameras
  • Usage documentation provided for all modes

Camera Modes

  • Stationary: The camera is fixed in space and isn't allowed to move. All user input is ignored.
  • FreeRotate: The camera is fixed in space, but the user is allowed to rotate it.
  • Fly: The user may control the camera using Forward/Backward/Left/Right/Up/Down. Controls are relative to the camera's current view direction - forward moves the camera toward whatever it's looking at.
  • OrbitObject: The camera is fixed in orbit around a particular object, with optional offset. The user may control the camera's angle, but not what the camera is looking at. If another object comes between the camera and orbited object, the camera will move inward so that its view is unobstructed.
  • OrbitPoint: Similar to OrbitObject, except that instead of orbiting an object (which may be mobile), the camera orbits a fixed point in the world. If an object comes between the camera and the orbited point, the camera will move inward so that its view is unobstructed.
  • TrackObject: The camera is fixed in space, and rotates to keep a particular object in the center of view( again, with optional offset). Like the Stationary mode, user input is ignored.
  • Overhead: The user may control the camera using Forward/Backward/Left/Right/Up/Down. Unlike the Fly camera, Forward/Backward/Left/Right movement is constrained to a horizontal plane.
  • EditOrbit: A special mode used by the World Editor. Should not be used outside of it.

Toggling Basic Camera Modes

The camera mode may be set by using the camera.cameraMode member field, or using a member function that sets the mode. For instance, Stationary, FreeRotate, Fly and Overhead modes may be set directly using this function:


Code Sample 1

function serverCmdSetCameraMode(%client, %cameraMode)
{
   %client.camera.setVelocity("0 0 0");

   %client.camera.controlMode = %cameraMode;

   %client.setControlObject(%client.camera);
}


With the code above implemented at the end of game/server/scripts/camera.cs, you can set the camera mode using a single function call:


Code Sample 2

// Overhead mode
commandToServer('SetCameraMode', "Overhead");

// Stationary Mode
commandToServer('SetCameraMode', "Stationary");

// Free Rotate Mode
commandToServer('SetCameraMode', "FreeRotate");

// Fly Mode
commandToServer('SetCameraMode', "Fly");

Toggling Special Camera Modes

OrbitObject, OrbitPoint and TrackObject require additional information to operate, and thus must be set with method calls:


setOrbitObject(GameBase, Point3F, float, float, [float], [bool], [Point3F], [bool])

Puts the camera in OrbitObject mode around the specified object:

Syntax

setOrbitObject(GameBase orbitObject, Point3F rotation, float minDistance, float maxDistance, float curDistance, bool ownClientObject, Point3F offset, bool locked)

  • orbitObject: The object to orbit. If the object is a ShapeBase, camera orbits its eye point. Otherwise, orbits the object's center.
  • rotation: Rotation vector of the camera (pitch, roll, yaw) in radians
  • minDist: Minimum distance between object and camera
  • maxDist: Maximum distance between object and camera
  • curDist: Optional. Initial distance between object and camera (defaults to %maxDist)
  • ownClientObject: Optional. True if the client owns the object being viewed (defaults to false)
  • offset: Optional. Offset from the object's center/eye point that the camera should focus on (defaults to "0 0 0")
  • locked: Optional. If true, the camera angle can't be controlled by the user (defaults to false)


Returns
No return value.

Examples

// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setOrbitObject(%this.player, mDegToRad(60) @ " 0 0", 0, 30, 30);


setOrbitPoint(string, float, float, [float], [Point3F], [bool])

Puts the camera in OrbitObject mode around the specified object:

Syntax

setOrbitPoint(string xform , float minDistance, float maxDistance, float curDistance, Point3F offset, bool locked)

  • xform: A set of fields for position and rotation: "posX posY posZ rotX rotY rotZ"
  • minDistance: Minimum distance to keep from point
  • maxDistance: Maximum distance to keep from point
  • curDistance: Optional. Initial distance from point (defaults to %maxDistance)
  • offset: Optional. Offset from the object's center/eye point that the camera should focus on (defaults to "0 0 0")
  • locked: Optional. If true, the camera angle can't be controlled by the user (defaults to false)


Returns
No return value.

Examples

// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setOrbitPoint("30 50 100 0 1 0", 0, 30, 30);


setTrackObject(GameBase, [Point3F])

Puts the camera in OrbitObject mode around the specified object:

Syntax

setTrackObject(GameBase object, Point3F offset)

  • object: The object to track. If the object is a ShapeBase, camera tracks its eye point. Otherwise, tracks the object's center.
  • offset: Optional. Offset from the object's center/eye point that the camera should focus on (defaults to "0 0 0")


Returns
No return value.

Examples

// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setTrackObject(%client.player);


setFlyMode(void)

Set the camera to be able to fly freely. Same as setting Camera.cameraMode value to "Fly"

Syntax

setTrackObject(void)

Returns
No return value.

Examples

// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setFlyMode();


setNewtonFlyMode(void)

Combination of setting Camera.newtonMode value to true and Camera.cameraMode value to "Fly"

Syntax

setNewtonFlyMode(void)

Returns
No return value.

Examples

// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setNewtonFlyMode();


Camera Options

Camera.newtonRotation and TrackObject mode produce a similar effect for rotation.


The Camera.newtonMode and Camera.newtonRotation member fields control how the camera moves and rotates. When Camera.newtonMode is set to true, the camera will use "smoothed" movement. Controls will affect the camera's acceleration rather than velocity. This gives the camera a sense of weight as it moves around. Camera.newtonRotation does the same thing, but for rotational controls. The following member fields only apply when either newtonMode or newtonRotation are set:

  • Camera.mass - Simulated mass of the camera
  • Camera.drag - Simulated drag when moving (not rotating)
  • Camera.force - Force on the camera when moving (not rotating)
  • Camera.angularDrag - Drag on camera when rotating
  • Camera.angularForce - Force on the camera when rotating (torque)
  • Camera.speedMultiplier - Factor to increase force by when trigger[0] is activated
  • Camera.brakeMultiplier - Factor to increase drag by when trigger[1] is activated


Enabling these flags can give different effects in different modes. For example:

"Tether Mode" - Achieved by enabling newtonMode and OrbitObject mode. The camera will still follow the orbited object, but with a springiness to it. This is best used with a massive camera, or with low moving force. Otherwise, the extra springiness will result in "Vomit-Vision."

Conclusion

Having Torque 3D's camera system exposed to script gives you a great deal of power and flexibility in your game. When you have tested the various modes, you can begin to see how this will affect game play.