Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

controller.first_person

First-person camera controller. Positions the camera at an entity's location (+ eye-height offset) and rotates with mouse look.

It resolves its follow target in this order: its own target field, then Camera.follow when target is unset, then the static posX/posY/posZ when neither is set. Camera.follow is the standard slot every behavior reads, so a first-person camera selected through Camera.behavior tracks whatever Camera.follow points at, the correct source for a player camera, whose body id is minted fresh per spawned clone and cannot be authored onto the behavior ahead of time.

Public fields: target (the entity to follow: the entity, its id or its name, kept as an entity reference; unset uses Camera.follow, then posX/Y/Z), posX, posY, posZ, offsetX, offsetY (eye height above target origin), offsetZ, sensitivity, minPitch, maxPitch.

Controls: pointer lock to rotate (yaw + pitch), which the standard scheme takes while the world runs. With the cursor handed back, an RMB drag rotates too — for as long as nothing else in the world binds the right button.

-- Track the Camera's follow target (set Camera.follow, no id authored here):
entity(id).component.add("controller.first_person", { offsetY = 1.6 })

-- Or a static camera at a fixed position:
entity(id).component.add("controller.first_person", { posX = 0, posY = 1.6, posZ = 3 })