Camera
The camera objects in YAHAHA are like windows into the 3D game world, offering different perspectives and views of the action. You can add multiple cameras to your scene, but only one can be active at any given time, acting as the game's "eye" on the world.
Key elements
The camera object's properties play a crucial role in defining the view and exploration of the 3D game world. The following are the most important properties:
- The Virtual Camera Name property identifies a virtual camera.
- The Camera Mode property offers pre-built camera options.
- The FOV property represents the extent of the observable world visible.
- The Follow Target property determines the target for the camera to follow.
- The LookAt Target property determines the target for the camera to stay focused on.
- The Enable Physics property controls whether the camera's collider is active.
How to work with the camera
Default camera
In each new project based on a template, a virtual camera named Default is automatically created. Similar to a camera in a 3D RPG, it provides a third-person perspective by following the player character from behind. It supports zooming, rotation around an avatar, and will be squeezed out when near colliders.
Adding camera
To create a camera:
-
For a quick setup, select a camera component from Asset Library, such as RTS, side-scroll, or top-down to easily get started.
-
For advanced configuration, use the camera module in Advanced Mode.
When using a camera component from Asset Library, it automatically generates a Default camera that cannot be renamed. To prevent conflicts, always remove any existing Default cameras added using camera components before creating a new one.
If you prefer more customization options, the camera module provides additional features. In addition to the Default camera, there are two built-in cameras named Gun and Car. You also have finer control of the camera. For instance, you can set the Camera Mode to EntityControl and use scripts to modify the attached object's transform, thereby controlling the camera's position and orientation.
Switching camera
To switch between cameras, call YaVirtualCameraAPI.ActiveCameraByEntity or YaVirtualCameraAPI.ActiveCameraByName.
Code sample
-- Client script :: When a trigger zone is activated, blend to the camera attached to the zone in 2 seconds
local self = script:SelfEntity()
PhysicsAPI.Instance(self):OnTriggerEnter(function(entity)
local character = YaScene:GetComponent(script:GetComponentType("YaCharacterComponent"), entity)
if character== nil then
return
end
YaVirtualCameraAPI.ActiveCameraByEntity(self,2)
end)
You can also set a new camera's name to Default in order to override the default camera's property values, thus offering a different game perspective.
Example cameras
Four example cameras configured using the camera module in Advanced Mode:
Third-person camera
Configurations | Game view |
---|---|
![]() | ![]() |
Note: If you set Min Distance, Max Distance, and Default Distance all to 0, and toggle off Enable Physics, you will get a first-person shooter (FPS) camera. This camera allows you to experience the game world from the perspective of the character, as if you were looking through their eyes.
RTS camera
Configurations | Game view |
---|---|
![]() | ![]() |
Fixed camera
Configurations | Game view |
---|---|
![]() | ![]() |
EntityControl camera
The camera's transform dynamically tracks an object's movement and rotation.
Configurations | Game view 1 | Game view 2 |
---|---|---|
![]() | ![]() | ![]() |
Use assemblers to set up cameras
Instead of attaching components, you can also use assemblers to set up main cameras that players can customize freely. These cameras do not include additional cinematic or scripted cameras used in narrative sequences.
To add these assemblers, open Asset Box, navigate to Logic > Assemblers, and locate the five camera assemblers. You can click on an assembler to set up and configure the camera.
Top-down 2D camera
A classic overhead view camera ideal for 2D top-down games.
Property | Description | Default (Near) | Default (Medium) | Default (Far) | Range |
---|---|---|---|---|---|
Depth (At depth) | Adjusts camera height (depth of field) | 3 | 6 | 9 | From 2 to 12 |
Field of view (FOV) | Controls the camera's viewing angle | 40 | 40 | 40 | From 30 to 60 |
View Control: Flexibility Preferred, allowing smooth and customizable camera movement.
Third-person 3D camera
A versatile camera following the player from behind, common in 3D action and adventure games.
Property | Description | Default (Near) | Default (Medium) | Default (Far) | Range |
---|---|---|---|---|---|
Default distance | Distance from the player | 3.5 | 5 | 6.5 | / |
Height offset | Vertical offset relative to player | 0.1 | 0.1 | 0.1 | From -0.5 to 0.5 |
Field of view (FOV) | Viewing angle of the camera | 40 | 40 | 40 | From 30 to 60 |
Enable physics | Enables physical collision for camera | Enabled | Enabled | Enabled | Enabled/Disabled |
Sensitivity | Camera rotation sensitivity | 0.3 | 0.3 | 0.3 | From 0.1 to 3 |
View Control: Flexibility Preferred, allowing smooth player input responsiveness.
Side-scroll 3D camera
A 3D camera designed for side-scrolling games, providing a fixed side view with depth.
Property | Description | Default (Near) | Default (Medium) | Default (Far) | Range |
---|---|---|---|---|---|
Depth (At depth) | Camera height or depth position | -5 | -7 | -9 | From -10 to -2 |
Field of view (FOV) | Camera viewing angle | 50 | 50 | 50 | From 30 to 60 |
View Control: Flexibility Preferred, allowing smooth side-scrolling gameplay.
Side-scroll 2D camera
A 2D side-scrolling camera with fixed depth positioning.
Property | Description | Default (Near) | Default (Medium) | Default (Far) | Range |
---|---|---|---|---|---|
Depth (At depth) | Camera height or depth position | -3 | -5 | -7 | From -10 to -2 |
View Control: Flexibility Preferred, allowing control to suit 2D side-scrolling mechanics.
RTS (Real-Time Strategy) camera
A strategic overhead camera with adjustable orientation and zoom, typical for RTS games.
Property | Description | Default (Near) | Default (Medium) | Default (Far) | Range |
---|---|---|---|---|---|
At orientation | Camera rotation angles (X, Y, Z) | 45°, 45°, 0° | 45°, 45°, 0° | 45°, 45°, 0° | / |
Default distance | Distance from the focus point | 4 | 7 | 10 | / |
Field of view (FOV) | Viewing angle | 40 | 40 | 40 | From 30 to 60 |
Sensitivity | Camera rotation sensitivity | 0.3 | 0.3 | 0.3 | From 0.1 to 3 |
View Control: Cursor Preferred, allowing precise camera manipulation.
Related documents
For more information on the camera module, see Camera module.
To learn how to use camera components from Asset Library, see Working with the camera.