camera.c

This script contains often used functions for a controlling a camera in relation to a target entity (usually the player). The functions are also used by the car templates. The script contains a startup function (camera_startup) that toggles between the 6 available camera modes with the [C] key, activates the individual modes with the [F1] .. [F6] keys, and allows to zoom with the mouse wheel.

Global parameters

Var Default Remarks
tcamera_mode
1
Initial and current camera mode (1..6), used by camera_startup; 0 for disabling camera_startup.
tcamera_dist
250
Distance between camera and player in all modes except the first person camera.
tcamera_height
50
Vertical distance between camera and player for the chase, orbit, and fixed camera.
tcamera_minDist
100
Minimum distance between camera and player.
tcamera_maxDist
2000
Maximum distance between camera and player.
tcamera_zoomDist
2
Sensitivity of the mouse wheel for adjusting the camera distance between the minimum and maximum.
tcamera_pos_x
0
X position for the fixed camera mode.
tcamera_pos_y
0
Y position for the fixed camera mode.
tcamera_offset_x
0
X offset for the first person camera.
tcamera_offset_y
10
Y offset for the first and 3rd person camera.
tcamera_offset_z
20
Z offset for the first person camera.
 
 
key_togglecamera
"c"
Key to toggle the camera mode.
joy_togglecamera
4
Joystick button to toggle the camera mode.
key_camera1
"f1"
Key to activate chase camera mode.
key_camera2
"f2"
Key to activate orbit camera mode.
key_camera3
"f3"
Key to activate fixed camera mode.
key_camera4
"f4"
Key to activate offset camera mode.
key_camera5
"f5"
Key to activate first person camera mode.
key_camera6
"f6"
Key to activate third person camera mode.

 

camera_chase(ENTITY*, var distance, var height)

Follow the entity with the camera, while keeping distance and height. Activated with the [F1] key in the camera_startup function.

camera_orbit(ENTITY*, var angle, var distance, var height)

Looks at the entity from a given pan angle (0 == behind), distance, and height. Activated with the [F2] key in the camera_startup function.

camera_face(ENTITY*, var height)

Looks at the entity from a fixed xy position (the current camera position) and a given height. Activated with the [F3] key in the camera_startup function.

camera_offset(ENTITY*, VECTOR* offset)

Looks at the entity from an offset position that moves with it. Activated with the [F4] key in the camera_startup function.

camera_person(ENTITY*, VECTOR* offset, var factor)

First or third person camera, looks in the same direction as the entity and moves with it with an offset. The factor (0..1) affects the influence of the entity's tilt and roll angle. First person mode is activated with the [F5] key, third person mode with the [F6] key in the camera_startup function.

Parameters

ent Target entity, usually the player.
height Vertical offset of the camera to the target entity.
angle Difference of camera angle and target entity angle.
dist Distance of the camera and the target entity.
offset Offset vector, relative position of the camera to the target entity.
factor Influence of the entity's tilt and roll angle, 0 = no influence, 1 = full influence.

Remarks

See Also:

car template, car.c, camera

► latest version online