The actores service
Reference for the actores service. Block characters driven by the script: rivals, neighbors, enemies.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
- Functions and properties of actores
- actores.crear
- actores.actor
- actores.existe
- actores.todos
- actores.en
- actores.alTocar
- actores.alEncontrarse
- actores.alTocarPieza
- actores.alEntrar
- actores.alSalir
- actores.alCaer
- Actor
- actor.tiene
- actor.etiquetar
- actor.desetiquetar
- actor.irA
- actor.seguirRuta
- actor.seguir
- actor.detener
- actor.mirarA
- actor.saltar
- actor.impulsar
- actor.eliminar
- Behavior notes
- Complete examples
- actores: script characters
- Next
Block characters driven by the script: rivals, neighbors, enemies. They use the same body and the same physics as a player (they walk, jump, fall and ride platforms), but they do not collide with players or with each other: you detect them with events. Up to 64 at once. They go away when the scene changes.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of actores#
actores.crear#
actores.crear(def: { id?; posicion: Vec3; rotacionY?; apariencia?: { torso?, piernas?, piel?, gorro? }; escala?; rapidez?; salto?; equipo?; etiquetas?; fisica?; datos? }): ActorCreates an actor. Only posicion is required: it is where its feet go.
From docs/EJEMPLOS.md, «actores: personajes del script»:
// Un vecino que saluda con su nombre y se pasea por la plaza.
const vecino = actores.crear({ id: 'vecino', posicion: [4, 0, 4], apariencia: { torso: 'cielo', gorro: 'ambar' }, rapidez: 3 });actores.actor#
actores.actor(id: string): ActorThe actor with that id. Fails with a clear message if it does not exist (use actores.existe to ask first).
actores.existe#
actores.existe(id: string): booleanTells whether an actor with that id exists.
actores.todos#
actores.todos(etiqueta?: string): Actor[]Every actor, or those with that tag.
actores.en#
actores.en(centro: Vec3, radio: number): Actor[]Actors closer than radio to a point.
actores.alTocar#
actores.alTocar(selectorDeActor: Selector, fn: (actor: Actor, jugador: Jugador) => void): voidA player starts touching an actor. The selector is an actor id or '#tag'.
From docs/EJEMPLOS.md, «actores: personajes del script»:
actores.alTocar('#enemigo', (enemigo, j) => { j.reaparecer(); enemigo.posicion = [10, 0, 10]; });actores.alEncontrarse#
actores.alEncontrarse(selectorDeActor: Selector, fn: (actor: Actor, otro: Actor) => void): voidTwo actors start touching. The selector picks the first one.
actores.alTocarPieza#
actores.alTocarPieza(selectorDePieza: Selector, fn: (pieza: Pieza, actor: Actor) => void): voidAn actor starts touching a piece. The selector is a piece selector: its id or '#tag'.
From docs/EJEMPLOS.md, «actores: personajes del script»:
actores.alTocarPieza('#trampa', (trampa, a) => { trampa.eliminar(); a.eliminar(); });actores.alEntrar#
actores.alEntrar(selectorDeZona: Selector, fn: (zona: Zona, actor: Actor) => void): voidAn actor enters a zone. The selector is a zone selector.
From docs/EJEMPLOS.md, «actores: personajes del script»:
// Un actor llega a una zona, toca una pieza o cae del mundo.
actores.alEntrar('base', (_zona, a) => { if (a.tiene('enemigo')) juego.terminar({ resultado: 'derrota' }); });actores.alSalir#
actores.alSalir(selectorDeZona: Selector, fn: (zona: Zona, actor: Actor) => void): voidAn actor leaves a zone. The selector is a zone selector.
actores.alCaer#
actores.alCaer(fn: (actor: Actor) => void): voidAn actor fell below alturaCaida: the room has already removed it.
From docs/EJEMPLOS.md, «actores: personajes del script»:
actores.alCaer((a) => juego.registro('cayo', a.id));Actor#
A block character controlled by the script. It walks with the same physics as a player.
| Property | Type | Description |
|---|---|---|
actor.id | string | Read-only. Id of the actor. If none was given on creation, the room assigned one. |
actor.existe | boolean | Read-only. false once it has been removed (or has fallen out of the world). |
actor.posicion | Vec3 | Position of the feet. Assigning it teleports the actor. |
actor.rotacionY | number | Where it faces, in degrees (0 is +Z). |
actor.velocidad | Vec3 | Velocity of the actor. |
actor.enSuelo | boolean | Read-only. true while standing on something. |
actor.suelo | Pieza | null | Read-only. The piece it is standing on, if any. |
actor.enCamino | boolean | Read-only. true while heading to a destination (irA, seguirRuta, seguir). |
actor.rapidez | number | Walking speed in units per second. Defaults to 5. |
actor.salto | number | Jump height. |
actor.equipo | string | Team name, free text. |
actor.nombre | Texto | null | Text floating above its head. null removes it. |
actor.apariencia | { torso?, piernas?, piel?, gorro? } | Colors of the actor: torso, legs, skin and hat. |
actor.visible | boolean | false: it is not drawn. |
actor.etiquetas | readonly string[] | Read-only. The tags of the actor. |
actor.datos | Record<string, unknown> | Free data for the script, per actor. |
actor.tiene#
actor.tiene(e: string): booleanTells whether the actor has that tag.
From docs/EJEMPLOS.md, «actores: personajes del script»:
// Un actor llega a una zona, toca una pieza o cae del mundo.
actores.alEntrar('base', (_zona, a) => { if (a.tiene('enemigo')) juego.terminar({ resultado: 'derrota' }); });actor.etiquetar#
actor.etiquetar(e: string): voidAdds a tag.
actor.desetiquetar#
actor.desetiquetar(e: string): voidRemoves a tag.
actor.irA#
actor.irA(destino: Vec3, opciones?: { tolerancia?: number; ruta?: boolean; alLlegar?: () => void }): voidWalks to a point. With ruta: true it goes around walls and gaps. Replaces the previous order.
actor.seguirRuta#
actor.seguirRuta(puntos: Vec3[], opciones?: { ciclo?: boolean; alLlegar?: () => void }): voidWalks through the points, in order. With ciclo, it returns to the first one forever (patrols).
From docs/EJEMPLOS.md, «actores: personajes del script»:
// Un vecino que saluda con su nombre y se pasea por la plaza.
const vecino = actores.crear({ id: 'vecino', posicion: [4, 0, 4], apariencia: { torso: 'cielo', gorro: 'ambar' }, rapidez: 3 });
// ...
vecino.seguirRuta([[4, 0, -4], [-4, 0, -4], [-4, 0, 4], [4, 0, 4]], { ciclo: true });actor.seguir#
actor.seguir(objetivo: Jugador | Actor | Pieza, opciones?: { distancia?: number; ruta?: boolean }): voidChases a player, another actor or a piece, until it is distancia away (1.5 by default).
From docs/EJEMPLOS.md, «actores: personajes del script»:
// Enemigos que persiguen al jugador rodeando los muros; tocar uno cuesta una vida.
for (let i = 0; i < 3; i++) {
const e = actores.crear({ posicion: [10 + i * 2, 0, 10], etiquetas: ['enemigo'], equipo: 'rojo', apariencia: { torso: 'coral', piernas: 'tinta' }, escala: 1.2 });
e.seguir(jugadores.todos()[0], { distancia: 0.8, ruta: true });
}actor.detener#
actor.detener(): voidStays where it is.
actor.mirarA#
actor.mirarA(objetivo: Vec3 | Jugador | Actor | Pieza): voidTurns to face a point, a player, an actor or a piece.
actor.saltar#
actor.saltar(): voidJumps, if it is on the ground.
actor.impulsar#
actor.impulsar(velocidad: Vec3): voidAdds velocity instantly.
actor.eliminar#
actor.eliminar(): voidRemoves the actor from the world.
From docs/EJEMPLOS.md, «actores: personajes del script»:
actores.alTocarPieza('#trampa', (trampa, a) => { trampa.eliminar(); a.eliminar(); });Behavior notes#
- An actor walks in a straight line and does not step into the void: it stops at an edge. It jumps steps that block its way. With
ruta: trueit goes around walls and gaps on the same level, using the same router as the test bot. - The animation (walking, jumping, falling) follows from its movement by itself.
fisica: falseleaves it floating wherever it is put (no gravity, no collisions): the script moves it withposicion, or withirA, which then goes straight.escalagoes from 0.4 to 3 (a big boss, a child).
Complete examples#
Complete scripts from docs/EJEMPLOS.md. Each one assumes a scene containing what it names, and the text keys (interfaz.t('...')) must exist in textos of juego.json.
actores: script characters#
import { actores, interfaz, juego, jugadores, mundo } from '@greengames/sdk';
juego.alIniciar(() => {
// Un vecino que saluda con su nombre y se pasea por la plaza.
const vecino = actores.crear({ id: 'vecino', posicion: [4, 0, 4], apariencia: { torso: 'cielo', gorro: 'ambar' }, rapidez: 3 });
vecino.nombre = interfaz.t('vecino');
vecino.seguirRuta([[4, 0, -4], [-4, 0, -4], [-4, 0, 4], [4, 0, 4]], { ciclo: true });
// Enemigos que persiguen al jugador rodeando los muros; tocar uno cuesta una vida.
for (let i = 0; i < 3; i++) {
const e = actores.crear({ posicion: [10 + i * 2, 0, 10], etiquetas: ['enemigo'], equipo: 'rojo', apariencia: { torso: 'coral', piernas: 'tinta' }, escala: 1.2 });
e.seguir(jugadores.todos()[0], { distancia: 0.8, ruta: true });
}
actores.alTocar('#enemigo', (enemigo, j) => { j.reaparecer(); enemigo.posicion = [10, 0, 10]; });
// Un actor llega a una zona, toca una pieza o cae del mundo.
actores.alEntrar('base', (_zona, a) => { if (a.tiene('enemigo')) juego.terminar({ resultado: 'derrota' }); });
actores.alTocarPieza('#trampa', (trampa, a) => { trampa.eliminar(); a.eliminar(); });
actores.alCaer((a) => juego.registro('cayo', a.id));
});Next#
- The camara service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.