The camera from a third person

Xtreme3D

Lesson 10
The camera from a third person

Level: medium
Version of the Xtreme3D: 3.0.x
Author: Gecko

Many games use the view from a third person, where the camera shows the character "from the back" is, for example, many game genres Action and RPG, 3D-type ����������� Spyro or Crash Bandicoot, Sports simulators, and so on. In this case, as a rule, the camera is not rigidly fixed at a certain distance from the character - it usually moves smoothly, with some delay that adds realism and �������������������.

The Xtreme3D similar to the operator to realize only slightly more complicated than the view from first person. The following code creates a hierarchy from the character, which the player will manage, and cameras, which will be for him to follow. As a symbol of the Character uses a simple cubic meters.

The code in the event Create:

Camera = CameraCreate(global.scene);
CameraSetViewDepth(Camera, 800);
CameraSetFocal(camera, 80);
ViewerSetCamera(view1, the camera);

Actor CubeCreate =(1, 1, 1, global.scene);

Target = DummycubeCreate(actor);
ObjectSetPosition(target, 0, 1, -4);
CameraSetTargetObject(camera, actor);

Code in the event of the Step:

If the keyboard_check(vk_up) ObjectMove(actor, 10 * dt);
If the keyboard_check(vk_down) ObjectMove(actor, -10 * dt);
If the keyboard_check(vk_left) ObjectTurn(actor, -200 * dt);
If the keyboard_check(vk_right) ObjectTurn(actor, 200 * dt);

Cx = ObjectGetAbsolutePosition(camera, 0);
Cy = ObjectGetAbsolutePosition(camera, 1);
Cz = ObjectGetAbsolutePosition(camera, 2);
Tx = ObjectGetAbsolutePosition(target, 0);
Ty = ObjectGetAbsolutePosition(target, 1);
The TZ = ObjectGetAbsolutePosition(target, 2);
Dx = tx - cx;
Dy = ty - cy;
Dz = the tz - cz;
ObjectTranslate(camera, dx *0.05, dy * 0.05, dz * 0.05);

The logic of the chamber is arranged so that its most long distance the distance from the character - when driving forward (so you can see what is happening around), and the closest - when driving in reverse. When turning the character the camera allows to consider it on the side. Approximately the same admission is used in racing simulations, so that, on the basis of this Code, it can be done and the engine races.