Log inGet started
World

Graybox FPS — v0.1 (fork)

Branchmain
Branchesmain
Commitc38143a9f7

README.md

game.rot

Rotations as values, so composing them is one call.

The engine's Transform quaternion builders publish four numbers rather than a table, and Transform.quatMul takes all eight of those numbers as separate arguments. That is fine at the API boundary and easy to get subtly wrong everywhere else — a single captured value silently becomes nil, and the entity ends up with an identity rotation where it should have had a pose.

This module is that boundary. Inside it a rotation is a table { x, y, z, w }; at the edges Rot.components(q) spreads one back into the four numbers an engine call wants. Angles are degrees, the unit the config is written in, converted once here at the point of use.

local Rot = require("game.rot")

local q = Rot.compose(Rot.pitch(12), Rot.roll(-4))
entity(id).localRotation = { Rot.components(q) }
CallWhat it makes
Rot.identity()No rotation
Rot.yaw(deg)About the world up axis
Rot.pitch(deg)About X — positive tips the front up
Rot.roll(deg)About Z — the cant of a gun in the hand
Rot.fromYawPitch(yaw, pitch)An aim rotation from two angles
Rot.compose(a, b)b applied first, then a
Rot.components(q)The four numbers, for an engine call
Rot.angles(q)Back to yawDeg, pitchDeg

Used by game.viewmodel, game.FpsCamera, game.Weapon, game.ShootingTarget and scenes.main's build.