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
reachandhalfAngleof a heading (heading 0 faces -z; see BGE.Math.isWithinArc()). - nearestInRect(): 2D - the nearest whose position is inside a rectangle.
Example
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 ifConstructor
new Interactables(): InteractablesInstance 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 usedid(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
BGE.Interactable— or invalid
count(): integer
Returns
integer
getAll(): Array.<BGE.Interactable>
Every interactable, in the order added.
Returns
Array.<BGE.Interactable>
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) — radiansreach(float)halfAngle(float) — radians either side of heading
Returns
BGE.Interactable— or invalid
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
BGE.Interactable— or invalid
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
target(BGE.Interactable)buttonText(string, optional, default: "\"OK\"")
Returns
string— "" for no target