Interactables

The things a player can talk to, open or pick up, and which one is "in front" right now. Entities that have been destroyed are skipped (and dropped by prune()).

  • nearestInArc(): 3D, on the ground plane - the nearest within reach and halfAngle of a heading (heading 0 faces -z; see BGE.Math.isWithinArc()).
  • nearestInRect(): 2D - the nearest whose position is inside a rectangle.

Example

CODE
m.talkers = new BGE.Interactables()
m.talkers.add(bram, "bram", "Talk to Bram", "bramNode")
target = m.talkers.nearestInArc(knight.position, knight.rotation.y, 3.5, BGE.Math.PI / 3)
if target <> invalid
prompt = m.talkers.promptFor(target, "OK") ' "OK: Talk to Bram"
end if

Constructor

new Interactables(): Interactables

Instance Methods

add( entity: BGE.GameEntity, id: string, label?: string, data?: dynamic, ): BGE.Interactable

Adds something to interact with. An existing one with the same id is replaced.

Parameters

  • entity (BGE.GameEntity) — its position is used
  • id (string)
  • label (string, optional, default: "\"\"")
  • data (dynamic, optional, default: "invalid")

Returns

remove(id: string): void

Parameters

  • id (string)

Returns

  • void

clear(): void

Returns

  • void

get(id: string): BGE.Interactable

Parameters

  • id (string)

Returns

count(): integer

Returns

  • integer

getAll(): Array.<BGE.Interactable>

Every interactable, in the order added.

Returns

prune(): void

Drops interactables whose entity has been destroyed.

Returns

  • void

nearestInArc( origin: BGE.Math.Vector, heading: float, reach: float, halfAngle: float, ): BGE.Interactable

The nearest enabled interactable within reach of origin and halfAngle of heading, on the ground plane (x/z).

Parameters

  • origin (BGE.Math.Vector)
  • heading (float) — radians
  • reach (float)
  • halfAngle (float) — radians either side of heading

Returns

nearestInRect( x: float, y: float, width: float, height: float, originX: float, originY: float, ): BGE.Interactable

The enabled interactable nearest (x/y) to originX, originY whose position is inside the rectangle from (x, y) to (x + width, y + height).

Parameters

  • x (float)
  • y (float)
  • width (float)
  • height (float)
  • originX (float)
  • originY (float)

Returns

promptFor(target: BGE.Interactable, buttonText?: string): string

A prompt for the target, e.g. "OK: Talk to Bram" (just the label if buttonText is "").

Parameters

Returns

  • string — "" for no target