voxel-controls
Manipulate voxel-physicals objects using
a state object. implements basic FPS controls. is a through
stream of sorts -- it relies
on voxel-engine to call control.tick(dt)
to start producing events. it will buffer events
when paused.
based on voxel-control by chrisdickinson except integrates with voxel-physicals instead of voxel-physical
options
// default values are in terms of 1 voxel width speed: Number00032 // starting speed walkMaxSpeed: Number00056 // max walking speed runMaxSpeed: Number00112 // max running speed jumpMaxSpeed: Number0016 // max jump speed jumpMaxTimer: Number200 // maximum amount of time jump will be applied in MS jumpSpeed: Number0004 // starting jump speed jumpSpeedMove: Number01 // velocity modifier to use when moving laterally while in the middle of a jump accelTimer: Number200 // time to reach full speed on X/Y accelerationCurve: Function // function(current, max) -> [0-1] // defaults to a sin curve. airControl: Booleantrue // can player control direction without being on the ground? fireRate: Number0 // MS between firing discreteFire: Booleanfalse // does firing require mousedown -> mouseup, or can it be held? onfire: Function // function(state) -> undefined rotationXMax: Number33 // maximum x rotation in a tick rotationYMax: Number33 // maximum y rotation in a tick rotationZMax: Number33 // maximum z rotation in a tick rotationMax: Number33 // maximum rotation in a tick -- other // rotation maximums fallback to this value rotationXClamp: NumberMathPI / 2 // clamp x rotation to +/- this value rotationYClamp: NumberInfinity // clamp y rotation to this value rotationZClamp: Number0 // clamp z rotation to this value rotationScale: Number0002 // constant scale of rotation events, applied during tick
api
control(state, opts) -> Control
state
is a state object (probably supplied by kb-controls).
opts
is an object optionally containing any of the above.
Control#target(target?) -> target
target
is the object to be manipulated. Assumed to have .acceleration
, .velocity
, .rotation
, and .atRestY() -> -1, 0, 1
.
if a target is passed, set control to target that argument.
return the current target.
Control#tick(dt) -> undefined
advance the simulation. if there are any listeners for 'data'
, it will either buffer or emit a data event containing the control state at this tick.
interactStream.pipe(controls) -> controls
the interact module emits dx/dy/dz modifications from mouse movements / pointer lock; it can be piped to this stream.
license
MIT