Skip to main content

Class: Entity

entity.Entity

Represents a generic entity in 3D space.

Hierarchy

Constructors

constructor

โ€ข new Entity(position, collider, pieces?, mass?, name?)

Creates a new Entity instance with a position, bounding box and body pieces.

Parameters

NameTypeDefault valueDescription
positionvec2undefinedThe entity's position in world space
colliderColliderundefinedThe entity's bounding box
piecesShape[][]The entity's body pieces for rendering
mass?numberundefinedThe entity's mass in kg (0 for infinite mass)
namestring""A name which can be used to identify the entity

Overrides

RigidBody.constructor

Defined in

src/entity.ts:26

Properties

airFriction

โ€ข airFriction: number = 0

The damping applied to the object's linear velocity every physics update.

Inherited from

RigidBody.airFriction

Defined in

src/physics/object.ts:68


angularDamping

โ€ข angularDamping: number = 0

The damping applied to the object's angular velocity every physics update.

Inherited from

RigidBody.angularDamping

Defined in

src/physics/object.ts:97


angularVelocity

โ€ข angularVelocity: number = 0

The object's angular velocity in radians per second.

Inherited from

RigidBody.angularVelocity

Defined in

src/physics/object.ts:80


collider

โ€ข collider: Collider

The object's collider.

Inherited from

RigidBody.collider

Defined in

src/physics/collisionObject.ts:23


dynamicFriction

โ€ข dynamicFriction: number = 0.1

Coefficient of dynamic/kinetic friction.

This value should be between 0 and 1 for best results.

see Static And Kinetic Friction

Inherited from

RigidBody.dynamicFriction

Defined in

src/physics/object.ts:51


filter

โ€ข filter: CollisionFilter

The object's collision filter.

Inherited from

RigidBody.filter

Defined in

src/physics/collisionObject.ts:18


force

โ€ข force: vec2

The net force applied to the object in newtons.

Inherited from

RigidBody.force

Defined in

src/physics/object.ts:58


gravity

โ€ข gravity: vec2

The gravitational froce applied to the object.

Inherited from

RigidBody.gravity

Defined in

src/physics/object.ts:12


isDynamic

โ€ข isDynamic: boolean = true

Wether the body has dynamics or not.

Inherited from

RigidBody.isDynamic

Defined in

src/physics/rigidbody.ts:15


isStatic

โ€ข isStatic: boolean = false

Wether or not the object is static, static objects do not move during collisions.

Inherited from

RigidBody.isStatic

Defined in

src/physics/collisionObject.ts:38


isTrigger

โ€ข isTrigger: boolean = false

Wether or not the collision object should be a trigger.

When true the object will detect but not respond to collisions.

Inherited from

RigidBody.isTrigger

Defined in

src/physics/collisionObject.ts:45


listeners

โ€ข Protected listeners: Object = {}

Index signature

โ–ช [index: string]: Listener[]

Inherited from

RigidBody.listeners

Defined in

src/object2d.ts:32


lockRotation

โ€ข lockRotation: boolean = false

Wether or not the object can rotate.

When true the object's rotation will not be affected by collisions or dynamics.

Inherited from

RigidBody.lockRotation

Defined in

src/physics/object.ts:125


lockXAxis

โ€ข lockXAxis: boolean = false

Wether or not the object's x position is locked.

When true the object's x position will not be affected by collisions or dynamics.

Inherited from

RigidBody.lockXAxis

Defined in

src/physics/object.ts:111


lockYAxis

โ€ข lockYAxis: boolean = false

Wether or not the object's y position is locked.

When true the object's y position will not be affected by collisions or dynamics.

Inherited from

RigidBody.lockYAxis

Defined in

src/physics/object.ts:118


name

โ€ข name: string = ""

Defined in

src/entity.ts:12


pieces

โ€ข Private pieces: Shape[]

Defined in

src/entity.ts:14


restitution

โ€ข restitution: number = 0

Elasticity/bounciness

This value should be between 0 and 1 for best results.

Inherited from

RigidBody.restitution

Defined in

src/physics/object.ts:33


staticFriction

โ€ข staticFriction: number = 0.1

Coefficient of static friction.

This value should be between 0 and 1 for best results.

see Static And Kinetic Friction

Inherited from

RigidBody.staticFriction

Defined in

src/physics/object.ts:42


stickyCollider

โ€ข stickyCollider: boolean = true

Wether or not to clone the object's position and rotation to it's collider.

Inherited from

RigidBody.stickyCollider

Defined in

src/physics/collisionObject.ts:33


takesGravity

โ€ข takesGravity: boolean = true

Wether or not the object should take gravity from the physics world.

Inherited from

RigidBody.takesGravity

Defined in

src/physics/object.ts:104


torque

โ€ข torque: number = 0

The object's torque in newtons, can be thought of as rotational force.

Inherited from

RigidBody.torque

Defined in

src/physics/object.ts:75


totalContacts

โ€ข totalContacts: number = 0

The number of contact points the object is colliding at.

Inherited from

RigidBody.totalContacts

Defined in

src/physics/collisionObject.ts:28


velocity

โ€ข velocity: vec2

The object's velocity in world space units (metres).

Inherited from

RigidBody.velocity

Defined in

src/physics/object.ts:63


zIndex

โ€ข Private zIndex: number = 0

Defined in

src/entity.ts:15

Methods

addEventListener

โ–ธ addEventListener(event, listener): boolean

Executes a function when an event is fired.

Parameters

NameTypeDescription
eventstringThe event to listen for
listenerListenerThe function to execute when the event fired

Returns

boolean

Wether or not the listener was added

Inherited from

RigidBody.addEventListener

Defined in

src/object2d.ts:209


addPiece

โ–ธ addPiece(piece): void

Adds a body piece to the entity.

Parameters

NameTypeDescription
pieceShapeThe piece to add to the entity

Returns

void

Defined in

src/entity.ts:98


applyForce

โ–ธ applyForce(force, contact?): void

Adds a force to the object's current total force vector.

If no contact point is provided then the force will be applied at the object's centre, generating 0 torque.

Parameters

NameTypeDescription
forcevec2The force vector to apply
contact?vec2The local position on the body to apply the force at

Returns

void

Inherited from

RigidBody.applyForce

Defined in

src/physics/object.ts:156


applyForceAtAngle

โ–ธ applyForceAtAngle(force, angle, contact?): void

Applies a force to the object at an angle.

The direction vector is calculated from the unit y+ vector.

If no contact point is provided then the force will be applied at the object's centre, generating 0 torque.

Parameters

NameTypeDescription
forcenumberThe force to apply in newtons
anglenumberThe angle at which to apply the force in radians (world space)
contact?vec2The local position on the body to apply the force at

Returns

void

Inherited from

RigidBody.applyForceAtAngle

Defined in

src/physics/object.ts:178


applyImpulse

โ–ธ applyImpulse(impulse, contactVector): void

Applies an impulse to the physics object.

This will apply an instantaneous change to the object's angular and linear velocity.

Parameters

NameTypeDescription
impulsevec2The impulse to apply
contactVectorvec2A vector from the object's center to the contact point

Returns

void

Inherited from

RigidBody.applyImpulse

Defined in

src/physics/object.ts:199


fireEvent

โ–ธ fireEvent(event, ...e): void

Executes all listeners attached to a given event.

Parameters

NameTypeDescription
eventstringThe event to fire
...eanyThe data to pass to each event listener

Returns

void

Inherited from

RigidBody.fireEvent

Defined in

src/object2d.ts:185


fixedUpdate

โ–ธ fixedUpdate(delta): void

Fires the "fixedUpdate" event.

Parameters

NameTypeDescription
deltanumberThe time since the last fixed update

Returns

void

Defined in

src/entity.ts:62


getEventListeners

โ–ธ getEventListeners(event): Listener[]

Gets the listeners attached to an event.

Parameters

NameType
eventstring

Returns

Listener[]

An array of listeners attached to the given event

Inherited from

RigidBody.getEventListeners

Defined in

src/object2d.ts:198


getEvents

โ–ธ getEvents(): string[]

Gets the events that can be listened to on the object.

Returns

string[]

The events the object supports

Inherited from

RigidBody.getEvents

Defined in

src/object2d.ts:175


getInertia

โ–ธ getInertia(): number

Gets the moment of inertia of the object.

Returns

number

The inertia of the object

Inherited from

RigidBody.getInertia

Defined in

src/physics/object.ts:257


getInverseInertia

โ–ธ getInverseInertia(): number

Gets the inverse moment of inertia of the object (1 / inertia).

Returns

number

The inverse inertia of the object

Inherited from

RigidBody.getInverseInertia

Defined in

src/physics/object.ts:266


getInverseMass

โ–ธ getInverseMass(): number

Gets the inverse mass of the object (1 / mass).

Returns

number

The inverse mass of the object

Inherited from

RigidBody.getInverseMass

Defined in

src/physics/object.ts:234


getMass

โ–ธ getMass(): number

Gets the mass of the object.

Returns

number

The mass of the object

Inherited from

RigidBody.getMass

Defined in

src/physics/object.ts:225


getPieces

โ–ธ getPieces(): Shape[]

Gets the entity's body pieces.

Returns

Shape[]

The entity's pieces

Defined in

src/entity.ts:89


getPosition

โ–ธ getPosition(): vec2

Gets the object's position.

Returns

vec2

The object's position as a vec2

Inherited from

RigidBody.getPosition

Defined in

src/object2d.ts:82


getRotation

โ–ธ getRotation(): number

Gets the object's rotation as a number in radians relative to y+.

Returns

number

The object's rotation

Inherited from

RigidBody.getRotation

Defined in

src/object2d.ts:139


getZIndex

โ–ธ getZIndex(): number

Gets the entities z index.

Returns

number

The entities z index

Defined in

src/entity.ts:135


moveRight

โ–ธ moveRight(dist): void

Moves the object's position right (x+) relative to it's rotation.

Parameters

NameTypeDescription
distnumberThe distance to move right, can be + or -

Returns

void

Inherited from

RigidBody.moveRight

Defined in

src/object2d.ts:100


moveUp

โ–ธ moveUp(dist): void

Moves the object's position up (y+) relative to it's rotation.

Parameters

NameTypeDescription
distnumberThe distance to move up, can be + or -

Returns

void

Inherited from

RigidBody.moveUp

Defined in

src/object2d.ts:114


removeEventListener

โ–ธ removeEventListener(event, listener): boolean

Removes a listener from an event.

Parameters

NameTypeDescription
eventstringThe event the listener is attached to
listenerListenerThe listener to remove

Returns

boolean

Wether or not the listener was removed

Inherited from

RigidBody.removeEventListener

Defined in

src/object2d.ts:223


removePiece

โ–ธ removePiece(piece): boolean

Removes a body piece from the entity.

Parameters

NameTypeDescription
pieceShapeThe piece to remove from the entity

Returns

boolean

Wether or not the piece was removed

Defined in

src/entity.ts:108


render

โ–ธ render(): void

Renders the entity's pieces.

Returns

void

Defined in

src/entity.ts:69


rotate

โ–ธ rotate(angle): void

Increments the object's rotation by an angle in radians.

Parameters

NameTypeDescription
anglenumberThe angle to rotate by in radians

Returns

void

Inherited from

RigidBody.rotate

Defined in

src/object2d.ts:148


setInertia

โ–ธ setInertia(inertia): void

Sets the moment of inertia of the object.

Also computes the inverse inertia.

NOTE: Setting the inertia to 0 will act as infinite inertia.

Parameters

NameTypeDescription
inertianumberThe objects new inertia

Returns

void

Inherited from

RigidBody.setInertia

Defined in

src/physics/object.ts:247


setMass

โ–ธ setMass(mass): void

Sets the mass of the object in kg.

Also computes the inverse mass.

NOTE: Setting the mass to 0 will act as infinite mass.

Parameters

NameTypeDescription
massnumberThe objects new mass

Returns

void

Inherited from

RigidBody.setMass

Defined in

src/physics/object.ts:213


setPieces

โ–ธ setPieces(pieces): void

Sets the entity's body pieces.

Parameters

NameTypeDescription
piecesShape[]The entity's new pieces

Returns

void

Defined in

src/entity.ts:80


setPosition

โ–ธ setPosition(pos): void

Sets the object's position.

Also sets this.collider's position, if this.stickyCollider is true.

Parameters

NameTypeDescription
posvec2The object's new position

Returns

void

Inherited from

RigidBody.setPosition

Defined in

src/physics/collisionObject.ts:121


setPositionX

โ–ธ setPositionX(x): void

Sets the x component of the object's position.

Parameters

NameTypeDescription
xnumberThe object's new x coordinate

Returns

void

Inherited from

RigidBody.setPositionX

Defined in

src/object2d.ts:56


setPositionY

โ–ธ setPositionY(y): void

Sets the y component of the object's position.

Parameters

NameTypeDescription
ynumberThe object's new y coordinate

Returns

void

Inherited from

RigidBody.setPositionY

Defined in

src/object2d.ts:69


setRotation

โ–ธ setRotation(angle): void

Sets the object's rotation, in radians.

Also sets this.collider's rotation, if this.stickyCollider is true.

Parameters

NameTypeDescription
anglenumberThe object's new rotation angle (in radians)

Returns

void

Inherited from

RigidBody.setRotation

Defined in

src/physics/collisionObject.ts:133


setZIndex

โ–ธ setZIndex(zIndex): void

Sets the entites z index.

throws When validateZIndex returns a string.

Parameters

NameTypeDescription
zIndexnumberThe entites new zIndex

Returns

void

Defined in

src/entity.ts:123


setupEvents

โ–ธ Protected setupEvents(): void

Sets the events that can be attached to in listeners.

Returns

void

Overrides

RigidBody.setupEvents

Defined in

src/entity.ts:39


testCollision

โ–ธ testCollision(B): CollisionResult

Checks if this object's collider is colliding with another object's collider.

Parameters

NameTypeDescription
BCollisionObjectCollisionObject to test collisions against

Returns

CollisionResult

CollisionResult with the results of the test

Inherited from

RigidBody.testCollision

Defined in

src/physics/collisionObject.ts:75


translate

โ–ธ translate(v): void

Translates the object by the provided vector.

Parameters

NameTypeDescription
vvec2The vector to translate by

Returns

void

Inherited from

RigidBody.translate

Defined in

src/object2d.ts:91


update

โ–ธ update(delta): void

Updates the entity.

Also fires the "update" event.

Parameters

NameTypeDescription
deltanumberThe time since the last update

Returns

void

Defined in

src/entity.ts:53