LittleJS 1.30.0

Render3D

FirstPersonCamera3D

FirstPersonCamera3D - Look around with the mouse and move with the keys, with the camera at its position

  • Click to capture the mouse so looking needs no button held, Esc lets it go; holding the button looks too, for touch
  • WASD or the arrow keys walk level, or move the way it looks when fly is set
  • A gamepad's left stick moves and its right stick looks, the touch gamepad's too (moveStick, stick)
  • An EngineObject3D that moves by velocity3D, so give it a size3D and call setCollision to walk into solid objects instead of through them; walking keeps velocity3D.y, so render3D.gravity can pull it down
  • Starts from wherever render3D.camera is, so it can take over from another camera without a jump
  • A camera of the camera plugin: the newest made drives the view, after the objects move each update
  • As the child of an EngineObject3D, like a player on a ship, its yaw, pitch and walking are relative to the parent, so it turns and moves with it
  • Destroy it to hand the camera back

Extends EngineObject3D

Constructor

new FirstPersonCamera3D(pos3D, yaw, pitch)render3dExtras.js:1535

Create a first person camera, it drives render3D.camera every frame

pos3D Vector3 optional

Where the eye is, defaults to where the camera is now

yaw number optional

Radians around Y, defaults to the camera's

pitch number optional

Radians up from level, defaults to the camera's

const player = new FirstPersonCamera3D(vec3(0, 1.5, 5));
player.size3D = vec3(1); // bump into solid objects
player.collideAsSphere3D = true;
player.setCollision();

Members

Methods

Inherited from EngineObject3D

Inherited from EngineObject

Members

eyeHeight : numberrender3dExtras.js:1572

How far above its position the eye is, in its own space, so with a size3D the eye can sit toward the top of the body instead of its middle; keep it under half the body's height, or the eye is outside the body and sees through a ceiling it stands under

Move the way it looks, up and down included, instead of walking level

jumpSpeed : numberrender3dExtras.js:1568

Speed of a jump in world units a frame, 0 for none; Space or gamepad button 0 jumps while it stands on something, a height map, a voxel map, a mesh collider or a solid, see groundObject

lockPointer : booleanrender3dExtras.js:1559

Capture the mouse on a click, so looking needs no button held

lookSpeed : numberrender3dExtras.js:1553

How far a pixel of mouse movement turns the view

moveSpeed : numberrender3dExtras.js:1551

World units per frame at full speed

moveStick : numberrender3dExtras.js:1563

Which gamepad stick moves it, like the keys, 0 is usually the left one, -1 for none

Angle up from level, the mouse tilts it

Lowest and highest pitch

Which gamepad stick looks around, 1 is usually the right one, -1 for none

stickSpeed : numberrender3dExtras.js:1565

Radians a second a stick pushed all the way turns the view

Angle around Y, the mouse turns it

Methods

Make this the camera that drives the view

destroy(immediate)render3dExtras.js:1638

Let go of the mouse and stop driving the camera

immediate boolean optional

Camera controls draw nothing

Taking over from another camera, it keeps its own eye

Read the mouse and keys and move, called automatically each frame

Put the camera at the eye, called by the camera plugin after the objects update

updatePhysics()render3dExtras.js:1595

Move by velocity3D, and fall by render3D.gravity unless flying, called automatically each frame