The Entity in the Game that is used as camera for rendering the scene. The Entity must have a CameraComponent. If it doesn't or if this property is set to null, the scene will be rendered as if seen from a camera at an arbitrary position near the origin of the world.
The Input contains the current state of the input devices connected to the local machine: the keyboard, mouse, gamepads as well as a simplified generic controls object.
The Renderer contains all the settings that controls how the Game is rendered in 3D: the lights, colors, post-process effects, etc...
The Session contains information about the multiplayer/network aspect of the Game, like the list of connected Peers and their Users.
The UI (i.e user interface), lets you create visual elements in screen-space, like a heads up display.
The list of all the Entities in the Game.
The time difference, in seconds, between the start of the current frame and the previous one. As an example, a game running at 60 fps has a typical frame delta time of 0.016s.
The time at which the current frame started. This is expressed in seconds since the game started the first time (this time origin isn't affected when restarting the game in edit mode)
The number of Entities in the Game.
The Entity in the Game that represents the local player, or null if there's none. This is typically the user avatar's SkeletalObject. Internally, the playerEntity is the first Entity found in the Game with the 'player' tag.
A game-wide save data storage bucket specific to the current user. You can use this to persist data from one game session across to another.
Think of it like a save file.
Example usage:
// `data` can be any JSON-serializable value you like.
let data = { checkpoint: "house1", unlocks: ["bat", "hatchet"] };
// When you are ready to save the user's progress:
this.game.saveData.write(data);
// And then, to read the data back out later:
data = this.game.saveData.read();
For more information, see the documentation for SaveData.
Access parameters passed in the scriptURLParams field of the game URL. The format is scriptURLParams={<name>: <value>}
,
where <name>
is a string, and <value>
is any JSON serializable type.
Accessing parameters in a user script:
let motto = this.game.scriptURLParams.team.motto;
Adds the given Entity to the Game. A typical use case is to add a new Entity that has just been created either by hand (using the Entity constructor) or from a Template resource. Another use case it to re-add an Entity that previously got removed. The Entity can have children if, for example, it has been created from a complex Template. The options argument determines whether or not the Entity/Entities should be networked, and if so, what network settings to use.
The Entity/Entities to add
The options describing the network settings to use for adding this Entity/Entities
The Entity to add
If true, the Entity will be replicated over the network on all the other Peers in the Session. If false, the Entity will only exist on the local Peer.
If true, the transform of the Entity will automatically be replicated over the network to all the other Peers in the Session. This can be true only if the networked argument is true.
Creates an Entity (possibly with children) from the given Template and adds it to the Game.
The Template from which to create the Entity that gets added to the Game.
The options describing the network settings to use for adding this Entity/Entities and its optional placement in space.
The Template from which to create the Entity that gets added to the Game.
If true, the Entity will be replicated over the network on all the other Peers in the Session. If false, the Entity will only exist on the local Peer.
If true, the transform of the Entity will automatically be replicated over the network to all the other Peers in the Session. This can be true only if the networked argument is true.
If provided, use this Vector3 as the world position of the newly created root Entity. If not, use the position from the Template.
If provided, use this Euler as the world rotation of the newly created root Entity. If not, use the rotation from the Template.
If provided, use this Vector3 as the world scale of the newly created root Entity. If not, use the scale from the Template.
Converts the point expressed in canvas space, i.e in CSS pixels from the top-left corner, into world space. The conversion uses the CameraComponent of this.game.cameraEntity. If this is null, or if the cameraEntity doesn't have a CameraComponent, the method returns null. Be aware that this method will still return a world point even if the point isn't visible in the canvas/camera, that is to say if the given canvas point lies outside the canvas rectangle (this can happen with mouse coordinates when left-click dragging outside the window) or if the the provided NDC z coordinate is outside the [-1, 1] range. This is a helper method, internally it takes the canvas point, converts it to clip space using game.renderer.canvasToClipSpace(), and convert the clip space point to world space using CameraComponent.clipSpaceToWorld().
➡️ See usage examples in the API Demo: Game canvas functions world.
The canvas point, in CSS pixels from the top-left corner, to convert to world space.
The optional Z coordinate to use for the intermediate NDC (normalized device coordinate) point. A value of -1 places it on the camera near plane, while a value of 1 places it on the far plane.
When provided, return the world point into this Vector3 instead of allocating one. Be aware that even if you provide this argument, you should still check the return value for null.
Creates a Ray in world space which origin is the given canvas point (converted in world space on the near plane) and which direction is the vector going from the camera to that point, normalized. The CameraComponent used for the calculations is the one currently defined by this game.cameraEntity. If this is null, or if the cameraEntity doesn't have a CameraComponent, a default Ray is returned.
➡️ See usage examples in the API Demo: Game canvas functions world.
The point in canvas space, in CSS pixels from the top-left corner, from which to create the Ray.
When provided, the ray is returned in this Ray object instead of allocating a new one.
Gets the Entities of the Game with the given tag.
➡️ See usage examples in the API Demo: Game tag functions world.
The tag the Entities to get should have.
Gets the Entities of the Game which CollisionComponent's collider intersects with the given capsule volume (i.e. a cylinder with hemispherical ends). The result is provided as an array of ColliderIntersection objects. Each one tells which Entity has been hit and where exactly in the capsule it happened. The ColliderIntersection objects in the resulting array are sorted by increasing distance to the start point of the capsule axis. Use the Game.getEntitiesWithVoxelObject-flavored static methods to intersect against the visual VoxelObjects of Entities rather than their colliders.
The line segment, expressed in world space, representing the cylindrical part of the capsule (i.e. the length of the capsule without the two hemispheres).
The radius, expressed in world space, of both the cylinder and hemispherical parts of the capsule. This defines how thick the capsule is.
When provided, only the colliders matching this collision layer(s) are be considered on the Entity. When not provided, all colliders are considered.
Gets the Entities of the Game which CollisionComponent's collider intersects with the given line segment. The result is provided as an array of ColliderIntersection objects. Each one tells which Entity has been hit and where exactly on the ray it happened. The ColliderIntersection objects in the resulting array are sorted by increasing distance to the start point of the line segment. Use the Game.getEntitiesWithVoxelObject-flavored static methods to intersect against the visual VoxelObjects of Entities rather than their colliders.
The line segment, expressed in world space, against which Entities are tested for intersection.
When provided, only the colliders matching this collision layer(s) are be considered on the Entity. When not provided, all colliders are considered.
Gets the Entities of the Game which CollisionComponent's collider intersects with the given ray. The result is provided as an array of ColliderIntersection objects. Each one tells which Entity has been hit and where exactly on the ray it happened. The ColliderIntersection objects in the resulting array are sorted by increasing distance to the origin of the ray. Use the Game.getEntitiesWithVoxelObject-flavored static methods to intersect against the visual VoxelObjects of Entities rather than their colliders.
The ray, expressed in world space, against which the Entities are tested for intersection.
If provided, the ray effectively behaves as a line segment starting from its origin and ending at this rayLength world units along the direction. If not provided, the ray starts at its origin and has an infinite length.
When provided, only the colliders matching this collision layer(s) are be considered on the Entity. When not provided, all colliders are considered.
Gets the Entities of the Game which CollisionComponent's collider intersects with the given sphere volume (i.e. are totally or partially overlapping it). The Entities in the resulting array are not provided in any particular order.
The sphere, expressed in world space, against which the Entities of the Game are tested for intersection.
When provided, only the colliders matching this collision layer(s) are be considered on the Entity. When not provided, all colliders are considered.
Gets the Entity in the Game with the given id, or null if there's no Entity with such id. Entities are assigned a unique id at creation so there can't be multiple Entities with the same id.
The id of the Entity to look for.
Gets the index-th Entity in the list of all the Entities of the Game (see the entities property).
The index of the requested Entity.
Redirects the browser to the given game. Usage example:
this.game.redirectToGame("ee6c009c342f4176a6debbd7b3d997a3", "escapethealiens", {"team: "blue"})
The unique id of the game you want to go to. You can find this in the game's URL, after "game/". For example, given the URL:
https://dotbigbang.com/game/ee6c009c342f4176a6debbd7b3d997a3?mp=escapethealiens
"ee6c009c342f4176a6debbd7b3d997a3"
.(Optional) The name of the multiplayer session you want to join. For example, given the URL:
https://dotbigbang.com/game/ee6c009c342f4176a6debbd7b3d997a3?mp=escapethealiens
"escapethealiens"
.(Optional) scriptURLParams to pass to the game you're redirecting to. This should be a JSON serializable object.
Removes the given Entity from the Game. If the Entity is networked, it is also automatically removed from the other Peers in the Session.
The Entity to remove
Calls the method specified by its name on all UserScriptComponents of all the Entities of the Game with the given tag. If a UserScriptComponent doesn't implement a method with that name, it's just skipped. The extra arguments after the method name are used as the arguments of the method to be called on each UserScriptComponent.
➡️ See usage examples in the API Demo: Game tag functions world.
The tag used to select which Entities in the Game should receive the event.
The name of the method to try to call on each UserScriptComponent of the Entities of interest, defined by the tag.
The arguments to pass to the method to be called on the UserScriptComponents.
Converts the point expressed in world space into canvas space (i.e in CSS pixels from the top-left corner). The conversion uses the CameraComponent of this.game.cameraEntity. If this is null, or if the cameraEntity doesn't have a CameraComponent, the method returns null. If the world point isn't inside the camera frustum, i.e. can't be seen on the canvas, the method also returns null. This is a helper method, internally it takes the world point, converts it to clip space using CameraComponent.worldToClipSpace(), and convert the clip space point to canvas space using game.renderer.clipSpaceToCanvas().
The world point to convert to canvas space.
When provided, return the canvas point into this Vector2 instead of allocating one. Be aware that even if you provide this argument, you should still check the return value for null.
Returns the closest point on the surface of the specified Entity's collider to the given point. Returns null if the Entity doesn't have a CollisionComponent or if the CollisionComponent's collider is NONE or VOXELOBJECT (which isn't supported yet). The point is returned in world space.
The point, in world space, from which to find the closest point.
When provided, only the colliders matching this collision layer(s) are be considered on the Entity. When not provided, all colliders are considered.
Gets the Entities of the given list which have their VoxelObjectComponent's VoxelObject intersected by the given line segment. The intersection is calculated between the line segment and the current VoxelObject frame of the first VoxelObjectRenderer component of each Entity. If an entity of the list is tagged with "noraycast", it is skipped and not considered for intersection. The VoxelObjectIntersection objects in the resulting array are sorted by increasing distance to the line segment start point. Use getEntitiesWithCollider-flavored methods for intersecting with the CollisionComponent's collider rather than the visual VoxelObject of the Entities.
The list of Entities against which to perform the intersection test. If possible, avoid testing against all the Entities of the Game as this can be costly. Instead, you might want to first use a broad volume intersection test (i.e. like getEntitiesWithColliderIntersectingSphere) to get a small set of Entities to test against.
The line-segment, expressed in world space, against which Entities are tested for intersection.
Gets the Entities of the given list which have their VoxelObjectComponent's VoxelObject intersected by the given ray. The intersection is calculated between the ray and the current VoxelObject frame of the first VoxelObjectRenderer component of each Entity. If an entity of the list is tagged with "noraycast", it is skipped and not considered for intersection. The VoxelObjectIntersection objects in the resulting array are sorted by increasing distance to the origin of the ray. Use getEntitiesWithCollider-flavored methods to intersect against the CollisionComponent's collider rather than the visual VoxelObject of the Entities.
The list of Entities against which to perform the intersection test. If possible, avoid testing against all the Entities of the Game as this can be costly. Instead, you might want to first use a broad volume intersection test (i.e. like getEntitiesWithColliderIntersectingSphere) to get a small set of Entities to test against.
The ray, expressed in world space, against which Entities are tested for intersection.
If provided, the ray effectively behaves as a line segment starting from its origin and ending at this rayLength world units along the direction. If not provided, the ray starts at its origin and has an infinite length.
Audio contains methods for manipulating the audio context of the game, and for playing back Sounds.