Scene access and play camera
Overview
Section titled “Overview”SDK 1.3 adds two things. host.Scene reads scene actors (cameras · paths · trigger zones · displays …), and host.View reads the play state and clock and moves the viewport camera during Play. With these you can build camera work such as orbits, zooms and path following in the Play preview. Write "sdk": "^1.3" in plugin.json.
Basic use
Section titled “Basic use”Typing myorbit in the console creates a camera that circles (0, 70, 0) for 6 seconds during Play.
-
In
Register, register a command,PlayChangedandPlayTicked.double t = 0; bool on = false;host.AddCommand(new NpCommand("myorbit", "myorbit", "6-second orbit camera during Play", _ =>{if (!host.View.Playing) return "Not playing";on = true; t = 0; return "Started";}));host.View.PlayChanged += playing => { if (!playing) on = false; };host.View.PlayTicked += dt =>{if (!on) return;t += dt;var c = new NpVec3(0, 70, 0);var eye = new NpVec3(c.X + 30 * (float)Math.Cos(t), 85, c.Z + 30 * (float)Math.Sin(t));host.View.LookAt(eye, c, fov: 60);if (t > 6) { on = false; host.View.ReleaseCamera(); }}; -
Build, then click Reload (selected) in the Plugin Manager.
-
Click the Play button (▶) on the main toolbar to start Play (Alt+P).
-
Type
myorbitin the Console. The camera circles for 6 seconds and then returns to the original view.
Tips and tricks
Section titled “Tips and tricks”- Once moved, the camera stays where it is. Create motion by calling
SetCamera·LookAtevery tick inPlayTicked. - Place a scene camera actor (
camera) and read its position and angle withhost.Scene.Find("<id>"), and you can line up shots by eye in the editor. Actorsreads the world again on every call. Do not call it every time insidePlayTicked; read it once onPlayChanged(true).- If you stop Play during a shot (Esc), the editor returns the camera to the original view and sends
PlayChanged(false). Clean up your state there. - The built-in action
cinematicalready handles multiple cameras, paths, holds and moves. If you register the same type withAddSceneEvent, it collides with the built-in type and the plugin does not enable, so for your own camera work, do not register a type; use onlyScene·View.
Reference
Section titled “Reference”Scene actors: INpScene
Section titled “Scene actors: INpScene”| Member | Type | Description |
|---|---|---|
Actors | IReadOnlyList<NpSceneActor> | All actors (in Outliner order). Each call returns a copy freshly read from the current world. |
Find(string id) | NpSceneActor? | Find by id. null if not found |
public sealed record NpSceneActor(string Id, string Kind, string Name, NpVec3 Pos, NpVec3 Rot, NpVec3 Size, string PropsJson = "{}");| Field | Description |
|---|---|
Id | Actor id (the name world logic uses) |
Kind | Kind (camera · path · trigger · blocker · display · text · spawn · light · particles · sound …). Block actors are included too, so filter by Kind. |
Name | Name shown in the Outliner |
Pos | Position (world coordinates, one block = 1) |
Rot | (yaw, pitch, roll) in Minecraft degrees |
Size | Box size for actors that have a box, such as trigger zones and blockers; otherwise the size scale |
PropsJson | Property object as a JSON string. "{}" if none |
- This is the authored state, not a pose moved by animation during Play.
- Read
PropsJsonwithSystem.Text.Json. Examples: a camera’sfov, a path’spoints(world coordinates[[x,y,z],…]).
foreach (var a in host.Scene.Actors) if (a.Kind == "camera") host.Log($"{a.Id} {a.Name} {a.Pos} yaw {a.Rot.X} pitch {a.Rot.Y}");
if (host.Scene.Find("route") is { } path){ using var doc = System.Text.Json.JsonDocument.Parse(path.PropsJson); if (doc.RootElement.TryGetProperty("points", out var pts)) host.Log($"{pts.GetArrayLength()} path points");}Angle rules
Section titled “Angle rules”| Value | Meaning |
|---|---|
| yaw 0 | Faces +Z (south) |
| yaw 90 | Faces −X (west) |
| pitch 0 | Horizontal |
| pitch 90 | Faces down |
These are the same rules as the angles on the Minecraft F3 screen. NpSceneActor.Rot and the angles of INpView use the same rules.
Viewport and Play: INpView
Section titled “Viewport and Play: INpView”| Member | Type | Description |
|---|---|---|
Playing | bool | Whether Play or Simulate is running |
PlayTime | double | Play clock (seconds). Starts at 0 and stops while paused. 0 when not playing |
CameraPos | NpVec3 | Current camera position |
CameraYaw · CameraPitch | float | Current camera angles (Minecraft degrees) |
CameraFov | float | Current field of view (degrees) |
SetCamera(NpVec3 pos, float yaw, float pitch, float fov = 0) | bool | Moves the camera to that position and direction. true on success |
LookAt(NpVec3 target, float fov = 0) | bool | Looks at target from the current position (where this plugin last put the camera) |
LookAt(NpVec3 eye, NpVec3 target, float fov = 0) | bool | Looks at target from eye |
ReleaseCamera() | void | Releases this plugin’s camera control (back to the original view) |
PlayChanged | event Action<bool>? | Play started (true) · ended (false) |
PlayTicked | event Action<double>? | Every tick of the play clock (0.05 seconds). Value = elapsed seconds |
Camera control rules
Section titled “Camera control rules”| Rule | Details |
|---|---|
| When it works | Only during Play or Simulate. Otherwise it returns false and does nothing. |
| Motion | One call leaves the camera at that position. To move it, call it every tick in PlayTicked. |
| First-person body | While the plugin moves the camera, the first-person body stops. |
fov | 0 or less = keep the current field of view. Other values are clamped to 30–110 degrees. |
| Invalid values | An infinite or NaN position, or a LookAt whose eye and target are the same, returns false |
| Restoring | On ReleaseCamera(), Play stop, plugin disable or isolation, the camera returns to the original view (Play = the body’s eye position, Simulate = free camera) and field of view. |
| Several controllers | Uses the same path as the built-in action cinematic preview. If several move the camera in the same tick, the last one wins. |
An example that zooms with a scene camera actor:
double zt = 0; bool zoom = false; // start with zoom = true from a command or similarhost.View.PlayTicked += dt =>{ if (!zoom) return; zt += dt; var cam = host.Scene.Find("cam_zoom_1"); if (cam == null) { zoom = false; return; } host.View.SetCamera(cam.Pos, cam.Rot.X, cam.Rot.Y, fov: 70 - (float)zt * 5); // zoom by narrowing the field of view if (zt > 6) { zoom = false; host.View.ReleaseCamera(); }};Cautions
Section titled “Cautions”PlayTickedis called every 0.05 seconds. Keep it light.- Camera work is for the editor preview. The camera on the game server is handled by the server plugin.
- There is no API for creating or moving scene actors. They are read-only.
Related pages
Section titled “Related pages”Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.