pub struct Ctx<'a> {
pub entity: Entity,
pub scene: &'a mut Scene,
pub input: &'a Input,
pub time: Time,
/* private fields */
}Expand description
What a script sees each call.
Fields§
§entity: EntityEntity owning this script slot; it may become stale if a script despawns it.
scene: &'a mut SceneMutable host scene. Register custom storages only in permanent host code.
input: &'a InputFrame snapshot and shared shell requests.
time: TimeScaled callback time.
Implementations§
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn ui(&self) -> &Canvas
pub fn ui(&self) -> &Canvas
The screen interface of this frame (see crate::canvas).
Sourcepub fn ui_width(&self) -> f32
pub fn ui_width(&self) -> f32
Width of the virtual interface screen (its height is always 720).
Sourcepub fn save_game(
&self,
slot: &str,
title: &str,
data: &Value,
) -> Result<(), String>
pub fn save_game( &self, slot: &str, title: &str, data: &Value, ) -> Result<(), String>
Writes a save slot (title is shown in load menus; the scene is recorded too).
Sourcepub fn save_slots(&self) -> Vec<SaveInfo>
pub fn save_slots(&self) -> Vec<SaveInfo>
Every save, newest first.
Sourcepub fn setting_f32(&self, key: &str, default: f32) -> f32
pub fn setting_f32(&self, key: &str, default: f32) -> f32
A persistent setting (kept across runs), or default.
Sourcepub fn setting_bool(&self, key: &str, default: bool) -> bool
pub fn setting_bool(&self, key: &str, default: bool) -> bool
A persistent on/off setting, or default.
Sourcepub fn setting_text(&self, key: &str, default: &str) -> String
pub fn setting_text(&self, key: &str, default: &str) -> String
A persistent text setting, or default.
Sourcepub fn set_setting(&self, key: &str, value: Value)
pub fn set_setting(&self, key: &str, value: Value)
Stores a persistent setting.
Sourcepub fn active_camera(&self) -> Option<Entity>
pub fn active_camera(&self) -> Option<Entity>
The camera the game looks through.
Sourcepub fn set_active_camera(&mut self, camera: Entity) -> bool
pub fn set_active_camera(&mut self, camera: Entity) -> bool
Looks through another camera from the next frame on (security monitors, cut-scenes…).
Sourcepub fn set_active_camera_named(&mut self, name: &str) -> bool
pub fn set_active_camera_named(&mut self, name: &str) -> bool
Switches to the camera named name.
Sourcepub fn add_camera_effect(
&mut self,
camera: Entity,
shader: &str,
params: [f32; 4],
) -> Option<usize>
pub fn add_camera_effect( &mut self, camera: Entity, shader: &str, params: [f32; 4], ) -> Option<usize>
Adds a camera shader (fn effect) to a camera; returns its index.
Sourcepub fn set_camera_effect(
&mut self,
camera: Entity,
index: usize,
enabled: bool,
params: [f32; 4],
)
pub fn set_camera_effect( &mut self, camera: Entity, index: usize, enabled: bool, params: [f32; 4], )
Changes the numbers of a camera shader (fade a VHS, pulse damage…).
Sourcepub fn set_camera_fov(&mut self, camera: Entity, fov: f32)
pub fn set_camera_fov(&mut self, camera: Entity, fov: f32)
Field of view of a camera in degrees (zoom, sprint effect).
Sourcepub fn camera_position(&self) -> Option<Vec3>
pub fn camera_position(&self) -> Option<Vec3>
World position of the active camera.
Sourcepub fn camera_forward(&self) -> Option<Vec3>
pub fn camera_forward(&self) -> Option<Vec3>
Direction the active camera looks along.
Sourcepub fn place_camera(&mut self, camera: Entity, position: Vec3, target: Vec3)
pub fn place_camera(&mut self, camera: Entity, position: Vec3, target: Vec3)
Places a camera and points it at a target (cut-scenes).
Sourcepub fn set_reverb(&mut self, amount: f32, room_ms: f32)
pub fn set_reverb(&mut self, amount: f32, room_ms: f32)
Room echo for sounds started from now on: amount 0..1, room_ms first reflection delay
(20 small room .. 120 hall). Call when the player enters a space.
Sourcepub fn set_volumes(&mut self, master: f32, music: f32, effects: f32)
pub fn set_volumes(&mut self, master: f32, music: f32, effects: f32)
Volumes of the mix: everything, music, other sounds (0..1, kept up to 2).
Sourcepub fn set_fullscreen(&self, on: bool)
pub fn set_fullscreen(&self, on: bool)
Switches the window to fullscreen or back.
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn dt(&self) -> f32
pub fn dt(&self) -> f32
Callback delta in seconds; fixed callbacks receive the configured fixed interval.
Sourcepub fn every(&self, seconds: f32) -> bool
pub fn every(&self, seconds: f32) -> bool
True once every seconds of game time (use inside update).
Sourcepub fn time_of_day(&self) -> f32
pub fn time_of_day(&self) -> f32
Current in-game hour, 0..24.
Sourcepub fn set_time_of_day(&mut self, hour: f32)
pub fn set_time_of_day(&mut self, hour: f32)
Jumps to an hour of the day (wraps into 0..24) and switches the procedural sky on.
Sourcepub fn set_day_speed(&mut self, hours_per_second: f32)
pub fn set_day_speed(&mut self, hours_per_second: f32)
Game hours that pass per real second (0 freezes the sun).
Sourcepub fn sky(&mut self) -> &mut SkySettings
pub fn sky(&mut self) -> &mut SkySettings
The whole sky configuration for fine control: clouds, stars, haze, aurora, moon.
Sourcepub fn set_clouds(&mut self, amount: f32)
pub fn set_clouds(&mut self, amount: f32)
0 = clear sky, 1 = overcast.
Sourcepub fn is_night(&self) -> bool
pub fn is_night(&self) -> bool
Whether it is night (sun below the horizon, roughly 20:00-05:00).
Sourcepub fn post(&mut self) -> &mut PostSettings
pub fn post(&mut self) -> &mut PostSettings
Screen effects for fine control: ctx.post().bloom = 0.8; ctx.post().motion_blur = 0.5;.
Sourcepub fn shadows(&mut self) -> &mut ShadowSettings
pub fn shadows(&mut self) -> &mut ShadowSettings
Sun shadow settings: ctx.shadows().softness = 2.0;.
Sourcepub fn post_preset(&mut self, name: &str)
pub fn post_preset(&mut self, name: &str)
Applies a ready-made look: “cinematic”, “dreamy”, “crisp”, “retro” or anything else for none.
Sourcepub fn set_exposure(&mut self, exposure: f32)
pub fn set_exposure(&mut self, exposure: f32)
Exposure multiplier (brightness) of the picture.
Sourcepub fn add_post_effect(&mut self, shader: &str) -> usize
pub fn add_post_effect(&mut self, shader: &str) -> usize
Adds a custom full-screen shader to the camera (a WGSL file with fn effect(..)) and returns its index.
Sourcepub fn set_post_effect_params(&mut self, index: usize, params: [f32; 4])
pub fn set_post_effect_params(&mut self, index: usize, params: [f32; 4])
Sets the four numbers a custom effect receives as params.
Sourcepub fn enable_post_effect(&mut self, index: usize, on: bool)
pub fn enable_post_effect(&mut self, index: usize, on: bool)
Switches a custom effect on or off.
Sourcepub fn clear_post_effects(&mut self)
pub fn clear_post_effects(&mut self)
Removes every custom camera effect.
Sourcepub fn play_sound(&mut self, clip: &str, volume: f32) -> SoundId
pub fn play_sound(&mut self, clip: &str, volume: f32) -> SoundId
Plays a clip (path inside assets/) in 2D, e.g. ctx.play_sound("sounds/click.wav", 1.0).
Sourcepub fn play_music(&mut self, clip: &str, volume: f32) -> SoundId
pub fn play_music(&mut self, clip: &str, volume: f32) -> SoundId
Plays a looping 2D clip (music). Keep the id to stop it with Self::stop_sound.
Sourcepub fn play_sound_at(
&mut self,
clip: &str,
volume: f32,
position: Vec3,
) -> SoundId
pub fn play_sound_at( &mut self, clip: &str, volume: f32, position: Vec3, ) -> SoundId
Plays a clip at a world position (distance falloff and left/right stereo).
Sourcepub fn play_sound_panned(
&mut self,
clip: &str,
volume: f32,
pan: f32,
) -> SoundId
pub fn play_sound_panned( &mut self, clip: &str, volume: f32, pan: f32, ) -> SoundId
Plays a clip with stereo position pan (-1 left .. 1 right).
Sourcepub fn play_sound_pitched(
&mut self,
clip: &str,
volume: f32,
pitch: f32,
) -> SoundId
pub fn play_sound_pitched( &mut self, clip: &str, volume: f32, pitch: f32, ) -> SoundId
Plays a clip with a pitch / speed multiplier.
Sourcepub fn stop_sound(&mut self, id: SoundId)
pub fn stop_sound(&mut self, id: SoundId)
Stops a sound started earlier.
Sourcepub fn set_sound_volume(&mut self, id: SoundId, volume: f32)
pub fn set_sound_volume(&mut self, id: SoundId, volume: f32)
Changes the volume of a running sound.
Sourcepub fn stop_all_sounds(&mut self)
pub fn stop_all_sounds(&mut self)
Stops every sound.
Sourcepub fn set_master_volume(&mut self, volume: f32)
pub fn set_master_volume(&mut self, volume: f32)
Master volume for the whole game, 0..1.
Sourcepub fn world(&mut self) -> &mut World
pub fn world(&mut self) -> &mut World
Mutable host world; its built-in component storages already exist.
Sourcepub fn log(&mut self, msg: impl Into<String>)
pub fn log(&mut self, msg: impl Into<String>)
Appends a message to the host log shown in the editor/player.
Sourcepub fn get<T: EcsComponent>(&self) -> Option<&T>
pub fn get<T: EcsComponent>(&self) -> Option<&T>
Borrows this entity’s component; returns None when missing or despawned.
Sourcepub fn get_mut<T: EcsComponent>(&mut self) -> Option<&mut T>
pub fn get_mut<T: EcsComponent>(&mut self) -> Option<&mut T>
Mutably borrows this entity’s component, if present.
Sourcepub fn get_of<T: EcsComponent>(&self, e: Entity) -> Option<&T>
pub fn get_of<T: EcsComponent>(&self, e: Entity) -> Option<&T>
Borrows another living entity’s component, if present.
Sourcepub fn get_mut_of<T: EcsComponent>(&mut self, e: Entity) -> Option<&mut T>
pub fn get_mut_of<T: EcsComponent>(&mut self, e: Entity) -> Option<&mut T>
Mutably borrows another living entity’s component, if present.
Sourcepub fn transform(&self) -> &Transform
pub fn transform(&self) -> &Transform
This entity’s transform (panics only if a script removed it; the editor does not allow that).
Sourcepub fn transform_mut(&mut self) -> &mut Transform
pub fn transform_mut(&mut self) -> &mut Transform
Sourcepub fn world_position(&self) -> Vec3
pub fn world_position(&self) -> Vec3
Current world position computed from the hierarchy, including pending local edits.
Sourcepub fn set_color(&mut self, e: Entity, rgba: [f32; 4])
pub fn set_color(&mut self, e: Entity, rgba: [f32; 4])
Sets the material colour of an entity (linear-ish sRGB, 0..1).
Sourcepub fn set_texture(&mut self, e: Entity, texture: &str)
pub fn set_texture(&mut self, e: Entity, texture: &str)
Sets a texture by asset path or by a procedural key (NoiseTexture::key()).
Sourcepub fn set_shape(&mut self, e: Entity, shape: Shape)
pub fn set_shape(&mut self, e: Entity, shape: Shape)
Replaces the mesh with a parametric shape (the mesh is rebuilt when parameters change).
Sourcepub fn children(&self, e: Entity) -> Vec<Entity>
pub fn children(&self, e: Entity) -> Vec<Entity>
Direct non-transient children in entity index order.
Sourcepub fn find(&self, name: &str) -> Option<Entity>
pub fn find(&self, name: &str) -> Option<Entity>
First exact entity-name match; names are not unique identifiers.
Sourcepub fn var(&self, entity: Entity, script: &str, name: &str) -> Option<Value>
pub fn var(&self, entity: Entity, script: &str, name: &str) -> Option<Value>
Reads a public variable (a field listed in the script’s fields()) of a script on any entity,
e.g. ctx.var(door, "DoorLogic", "locked"). Returns JSON: numbers, bools, strings, arrays.
Sourcepub fn set_var(
&mut self,
entity: Entity,
script: &str,
name: &str,
value: Value,
) -> bool
pub fn set_var( &mut self, entity: Entity, script: &str, name: &str, value: Value, ) -> bool
Changes a public variable of a script on any entity; the script sees it before its next callback. Returns false when the entity has no such script.
Sourcepub fn var_f32(&self, entity: Entity, script: &str, name: &str) -> Option<f32>
pub fn var_f32(&self, entity: Entity, script: &str, name: &str) -> Option<f32>
Number variable of another script, see Ctx::var.
Sourcepub fn var_bool(&self, entity: Entity, script: &str, name: &str) -> Option<bool>
pub fn var_bool(&self, entity: Entity, script: &str, name: &str) -> Option<bool>
Boolean variable of another script, see Ctx::var.
Sourcepub fn spawn(&mut self, name: &str) -> Entity
pub fn spawn(&mut self, name: &str) -> Entity
Creates a named entity with an identity local transform.
Sourcepub fn spawn_primitive(
&mut self,
name: &str,
primitive: &str,
position: Vec3,
) -> Entity
pub fn spawn_primitive( &mut self, name: &str, primitive: &str, position: Vec3, ) -> Entity
Creates a visible primitive at a world-space position with no collider/body.
Supported primitive names are listed in crate::mesh::PRIMITIVES.
Sourcepub fn despawn(&mut self, e: Entity)
pub fn despawn(&mut self, e: Entity)
Destroys an entity and its subtree. Physics objects are removed on the next fixed step.
Sourcepub fn add_impulse(&mut self, impulse: Vec3)
pub fn add_impulse(&mut self, impulse: Vec3)
Accumulates a world-space impulse for this body to consume on the next physics step.
Does nothing when no RigidBody is attached.
Sourcepub fn set_velocity(&mut self, v: Vec3)
pub fn set_velocity(&mut self, v: Vec3)
Requests a world-space linear velocity in metres/second for the next fixed step.
Sourcepub fn set_angular_velocity_of(&mut self, e: Entity, w: Vec3)
pub fn set_angular_velocity_of(&mut self, e: Entity, w: Vec3)
Sets the spin of a rigid body (any entity); Vec3::ZERO stops it rotating.
Sourcepub fn set_velocity_of(&mut self, e: Entity, v: Vec3)
pub fn set_velocity_of(&mut self, e: Entity, v: Vec3)
Sets the linear velocity of any rigid body.
Sourcepub fn velocity(&self) -> Vec3
pub fn velocity(&self) -> Vec3
Last simulated linear velocity, or zero when no body is attached.
Sourcepub fn raycast(
&self,
origin: Vec3,
dir: Vec3,
max_distance: f32,
) -> Option<RayHit>
pub fn raycast( &self, origin: Vec3, dir: Vec3, max_distance: f32, ) -> Option<RayHit>
First solid collider hit by the ray; this entity’s own collider and triggers are ignored.
Sourcepub fn raycast_filtered(
&self,
origin: Vec3,
direction: Vec3,
max_distance: f32,
options: QueryOptions,
) -> Option<RayHit>
pub fn raycast_filtered( &self, origin: Vec3, direction: Vec3, max_distance: f32, options: QueryOptions, ) -> Option<RayHit>
Ray query with layer/sensor filters; defaults to excluding this script’s body.
An explicit options.exclude overrides that default owner exclusion.
Sourcepub fn overlap_sphere_filtered(
&self,
center: Vec3,
radius: f32,
options: QueryOptions,
) -> Vec<Entity>
pub fn overlap_sphere_filtered( &self, center: Vec3, radius: f32, options: QueryOptions, ) -> Vec<Entity>
Sphere query under explicit layer/sensor/exclusion filters. No implicit owner exclusion.
Sourcepub fn overlap_sphere(&self, center: Vec3, radius: f32) -> Vec<Entity>
pub fn overlap_sphere(&self, center: Vec3, radius: f32) -> Vec<Entity>
Collider entities overlapping a world-space sphere in the last physics state. Includes triggers and this entity; results are sorted and deduplicated.
Sourcepub fn touching(&self, entity: Entity) -> Vec<Entity>
pub fn touching(&self, entity: Entity) -> Vec<Entity>
Active solid contacts and sensor overlaps for a collider entity.
Sourcepub fn is_alive(&self, entity: Entity) -> bool
pub fn is_alive(&self, entity: Entity) -> bool
Whether an entity handle still refers to a living object in this scene.
Sourcepub fn world_matrix_of(&self, entity: Entity) -> Mat4
pub fn world_matrix_of(&self, entity: Entity) -> Mat4
Current world matrix, evaluated directly from local transforms.
Sourcepub fn set_parent(&mut self, entity: Entity, parent: Option<Entity>) -> bool
pub fn set_parent(&mut self, entity: Entity, parent: Option<Entity>) -> bool
Reparents while preserving world pose when representable as TRS.
Sourcepub fn set_parent_local(
&mut self,
entity: Entity,
parent: Option<Entity>,
) -> bool
pub fn set_parent_local( &mut self, entity: Entity, parent: Option<Entity>, ) -> bool
Reparents while preserving local pose; rejects stale handles and cycles.
Sourcepub fn insert<T: EcsComponent>(&mut self, entity: Entity, component: T)
pub fn insert<T: EcsComponent>(&mut self, entity: Entity, component: T)
Adds a component of a host-registered type to a living entity.
§Panics
Panics for unregistered or conflicting component types; scripts use built-ins only.
Sourcepub fn remove<T: EcsComponent>(&mut self, entity: Entity) -> Option<T>
pub fn remove<T: EcsComponent>(&mut self, entity: Entity) -> Option<T>
Removes a component, returning its former value if present.
Sourcepub fn attach_script(&mut self, entity: Entity, name: &str) -> bool
pub fn attach_script(&mut self, entity: Entity, name: &str) -> bool
Adds a named script slot. The runtime creates its instance at the next sync. Returns false for a stale entity; duplicate names in different slots are allowed.
Sourcepub fn detach_script(&mut self, entity: Entity, name: &str) -> usize
pub fn detach_script(&mut self, entity: Entity, name: &str) -> usize
Removes every slot with this script name. Returns the number removed.
Sourcepub fn tagged(&self, tag: &str) -> Vec<Entity>
pub fn tagged(&self, tag: &str) -> Vec<Entity>
Snapshot of all living entities with an exact tag, in index order.
Sourcepub fn has_tag(&self, entity: Entity, tag: &str) -> bool
pub fn has_tag(&self, entity: Entity, tag: &str) -> bool
Whether an entity contains this exact group label.
Sourcepub fn add_tag(&mut self, entity: Entity, tag: &str) -> bool
pub fn add_tag(&mut self, entity: Entity, tag: &str) -> bool
Adds a group label, creating Tags if needed. Invalid/duplicate labels or stale entities return false.
Sourcepub fn remove_tag(&mut self, entity: Entity, tag: &str) -> bool
pub fn remove_tag(&mut self, entity: Entity, tag: &str) -> bool
Removes a label without removing other tags; returns whether it existed.
Sourcepub fn despawn_after(&mut self, entity: Entity, seconds: f32) -> bool
pub fn despawn_after(&mut self, entity: Entity, seconds: f32) -> bool
Schedules/replaces subtree expiration after non-negative simulation seconds. Zero expires after update callbacks in the current/next accepted frame. Invalid durations or stale entities return false without changing components.
Sourcepub fn set_visible(&mut self, entity: Entity, visible: bool) -> bool
pub fn set_visible(&mut self, entity: Entity, visible: bool) -> bool
Sets inherited mesh visibility without changing scripts, lights or physics. Returns false for a stale entity.
Sourcepub fn is_visible(&self, entity: Entity) -> bool
pub fn is_visible(&self, entity: Entity) -> bool
Effective mesh visibility, including hidden ancestors.
Sourcepub fn move_to(
&mut self,
entity: Entity,
target: Vec3,
seconds: f32,
ease: Ease,
) -> bool
pub fn move_to( &mut self, entity: Entity, target: Vec3, seconds: f32, ease: Ease, ) -> bool
Starts/replaces a parent-local position tween from the current pose. Returns false for invalid targets/durations, stale entities or missing transforms.
Sourcepub fn teleport_of(
&mut self,
entity: Entity,
position: Vec3,
reset_velocity: bool,
) -> bool
pub fn teleport_of( &mut self, entity: Entity, position: Vec3, reset_velocity: bool, ) -> bool
Moves an entity to a world-space point and queues physical teleportation.
With reset_velocity, pending impulses and both velocities are cleared.
For a dynamic body the final pose is integrated on the next fixed step;
non-physical entities move immediately. Invalid/singular requests do nothing.
Sourcepub fn teleport(&mut self, position: Vec3, reset_velocity: bool) -> bool
pub fn teleport(&mut self, position: Vec3, reset_velocity: bool) -> bool
Teleports this script’s entity, optionally resetting its motion.
Sourcepub fn emit(
&mut self,
channel: &str,
payload: Value,
) -> Result<u64, SignalError>
pub fn emit( &mut self, channel: &str, payload: Value, ) -> Result<u64, SignalError>
Broadcasts JSON data on a channel for delivery before the next frame’s callbacks. Sending is bounded and returns an explicit error rather than silently dropping data.
Sourcepub fn send_to(
&mut self,
target: Entity,
channel: &str,
payload: Value,
) -> Result<u64, SignalError>
pub fn send_to( &mut self, target: Entity, channel: &str, payload: Value, ) -> Result<u64, SignalError>
Sends a directed message to a living entity for the next simulation frame.
Sourcepub fn signals(&self, channel: &str) -> Vec<Signal>
pub fn signals(&self, channel: &str) -> Vec<Signal>
Clones the current channel messages addressed to this entity or broadcast. Owned snapshots let callbacks mutate the scene while handling messages. Reading does not consume signals; use update for one-shot processing.
Sourcepub fn key_pressed(&self, k: Key) -> bool
pub fn key_pressed(&self, k: Key) -> bool
Whether the physical key went down in this frame snapshot.
Sourcepub fn key_released(&self, key: Key) -> bool
pub fn key_released(&self, key: Key) -> bool
Whether the physical key went up in this frame snapshot.
Sourcepub fn mouse_down(&self, b: MouseButton) -> bool
pub fn mouse_down(&self, b: MouseButton) -> bool
Whether a physical pointer button is held.
Sourcepub fn mouse_pressed(&self, button: MouseButton) -> bool
pub fn mouse_pressed(&self, button: MouseButton) -> bool
Whether a physical pointer button went down this frame.
Sourcepub fn mouse_released(&self, button: MouseButton) -> bool
pub fn mouse_released(&self, button: MouseButton) -> bool
Whether a physical pointer button went up this frame.
Sourcepub fn lock_cursor(&self, lock: bool)
pub fn lock_cursor(&self, lock: bool)
Hides the cursor and keeps it centred while true; input.mouse_delta then is the look movement.
Sourcepub fn load_scene(&self, path: &str)
pub fn load_scene(&self, path: &str)
Switches to another scene once this frame ends, e.g. ctx.load_scene("scenes/level2.scene.json").
Objects and scripts of the current scene go away; the new scene starts with fresh scripts.
Sourcepub fn add_scene(&self, path: &str)
pub fn add_scene(&self, path: &str)
Adds every object of another scene to this one once this frame ends (a level piece, a shared menu…). Its scripts start on the next frame; the scene settings stay as they are.
Sourcepub fn reload_scene(&self)
pub fn reload_scene(&self)
Starts the running scene again from its file once this frame ends (restart a level).
Sourcepub fn scene_path(&self) -> String
pub fn scene_path(&self) -> String
Asset path of the running scene, e.g. scenes/main.scene.json (empty if unknown).
Sourcepub fn hud_prompt(&self, text: &str)
pub fn hud_prompt(&self, text: &str)
Shows the interaction hint on screen for this frame (“Press E to open”).
Sourcepub fn hud_message(&self, text: &str, seconds: f32)
pub fn hud_message(&self, text: &str, seconds: f32)
Displays a transient message for finite non-negative simulation seconds.
Sourcepub fn hud_objective(&self, text: &str)
pub fn hud_objective(&self, text: &str)
Replaces persistent HUD objective text; empty clears it.
Sourcepub fn hud_crosshair(&self, on: bool)
pub fn hud_crosshair(&self, on: bool)
Requests that the hosting shell show/hide the crosshair.
Sourcepub fn action_down(&self, name: &str) -> bool
pub fn action_down(&self, name: &str) -> bool
Named input actions from Project Settings > Input.
Sourcepub fn action_pressed(&self, name: &str) -> bool
pub fn action_pressed(&self, name: &str) -> bool
Whether any bound input went down this frame; missing actions return false.
Sourcepub fn action_released(&self, name: &str) -> bool
pub fn action_released(&self, name: &str) -> bool
Whether the last held input bound to this action was released.
Sourcepub fn action_vector(
&self,
left: &str,
right: &str,
down: &str,
up: &str,
) -> Vec2
pub fn action_vector( &self, left: &str, right: &str, down: &str, up: &str, ) -> Vec2
Unit-length two-dimensional movement from four named actions.
Sourcepub fn action_axis(&self, negative: &str, positive: &str) -> f32
pub fn action_axis(&self, negative: &str, positive: &str) -> f32
Digital axis: positive minus negative action, in [-1, 1].
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn position(&self) -> Vec3
pub fn position(&self) -> Vec3
World position of this entity (alias of Ctx::world_position).
Sourcepub fn position_of(&self, entity: Entity) -> Option<Vec3>
pub fn position_of(&self, entity: Entity) -> Option<Vec3>
World position of another entity, None when it is dead or has no Transform.
Sourcepub fn set_position(&mut self, position: Vec3) -> bool
pub fn set_position(&mut self, position: Vec3) -> bool
Moves this entity to a world position immediately (no physics teleport; see Ctx::teleport).
Sourcepub fn translate_local(&mut self, delta: Vec3)
pub fn translate_local(&mut self, delta: Vec3)
Moves along the entity’s own axes: translate_local(Vec3::NEG_Z * 2.0) goes 2 m forward.
Sourcepub fn rotate(&mut self, degrees: Vec3)
pub fn rotate(&mut self, degrees: Vec3)
Adds Euler degrees (pitch, yaw, roll) to the local rotation.
Sourcepub fn distance_to(&self, entity: Entity) -> Option<f32>
pub fn distance_to(&self, entity: Entity) -> Option<f32>
Straight-line distance to another entity, None when it cannot be measured.
Sourcepub fn direction_to(&self, target: Vec3) -> Vec3
pub fn direction_to(&self, target: Vec3) -> Vec3
Unit vector from this entity to a world point, zero when they coincide.
Sourcepub fn look_at(&mut self, target: Vec3)
pub fn look_at(&mut self, target: Vec3)
Turns the entity (yaw and pitch, no roll) so that its forward axis points at a world point. Assumes the parent is not rotated. Does nothing when the point is at the entity.
Sourcepub fn look_at_flat(&mut self, target: Vec3)
pub fn look_at_flat(&mut self, target: Vec3)
Like Ctx::look_at but ignores height: only the yaw changes (characters, turrets).
Sourcepub fn move_towards(&mut self, target: Vec3, speed: f32) -> bool
pub fn move_towards(&mut self, target: Vec3, speed: f32) -> bool
Walks towards a world point at speed metres per second (uses the callback dt).
Returns true once the point is reached. Moves the transform directly, so use it for
kinematic objects; dynamic bodies should use add_impulse or set_velocity.
Sourcepub fn nearest_tagged(&self, tag: &str) -> Option<(Entity, f32)>
pub fn nearest_tagged(&self, tag: &str) -> Option<(Entity, f32)>
The closest entity carrying tag (other than this one) and its distance.
Sourcepub fn despawn_self(&mut self)
pub fn despawn_self(&mut self)
Removes this entity (and its children) from the scene.
Sourcepub fn random(&self) -> f32
pub fn random(&self) -> f32
A random number in 0.0..1.0. Every call advances a shared stream, so values differ per call.
For a repeatable sequence keep a crate::random::Rng in your script instead.
Sourcepub fn random_range(&self, min: f32, max: f32) -> f32
pub fn random_range(&self, min: f32, max: f32) -> f32
A random number in min..max.
Source§impl Ctx<'_>
Hierarchy, tags and shared variables.
impl Ctx<'_>
Hierarchy, tags and shared variables.
Sourcepub fn descendants(&self, entity: Entity) -> Vec<Entity>
pub fn descendants(&self, entity: Entity) -> Vec<Entity>
Every entity below entity: children, grandchildren and so on.
Sourcepub fn find_child(&self, name: &str) -> Option<Entity>
pub fn find_child(&self, name: &str) -> Option<Entity>
The first descendant of this entity with the given name.
Sourcepub fn tagged_within(&self, tag: &str, center: Vec3, radius: f32) -> Vec<Entity>
pub fn tagged_within(&self, tag: &str, center: Vec3, radius: f32) -> Vec<Entity>
Entities carrying tag within radius metres of a world point, nearest first.
All tags of an entity.
Sourcepub fn play_animation(&mut self, entity: Entity, clip: &str) -> bool
pub fn play_animation(&mut self, entity: Entity, clip: &str) -> bool
Plays an animation clip on an object (cross-fading from the current one); adds an
crate::skeletal::Animator when the object has none. The model must have a skeleton:
clips from its file, or the procedural humanoid ones (Idle, Walk, Run, Talk,
Wave, Sit, Wipe, Look). Returns false for a stale entity.
Sourcepub fn set_animation_speed(&mut self, entity: Entity, speed: f32)
pub fn set_animation_speed(&mut self, entity: Entity, speed: f32)
Playback speed of an object’s animation (1 = as authored). Use it to match a walk cycle to the speed the object really moves at.
Sourcepub fn ragdoll(&mut self, entity: Entity, impulse: Vec3) -> bool
pub fn ragdoll(&mut self, entity: Entity, impulse: Vec3) -> bool
Makes an animated humanoid go limp: its body becomes physics capsules joined at the
joints, starting in the current pose and pushed by impulse (newton-seconds, world space).
Adds a crate::ragdoll::Ragdoll when there is none. Returns false for a stale entity.
Sourcepub fn stop_ragdoll(&mut self, entity: Entity)
pub fn stop_ragdoll(&mut self, entity: Entity)
Ends a ragdoll: the bodies are removed and the clip animates the character again.
Sourcepub fn look_at_point(&mut self, entity: Entity, point: Option<Vec3>)
pub fn look_at_point(&mut self, entity: Entity, point: Option<Vec3>)
Turns an animated humanoid’s head (and chest) towards a world point, or lets go with
None. Adds a crate::ik::CharacterIk when there is none.
Sourcepub fn animation_clips(&self, entity: Entity) -> Vec<String>
pub fn animation_clips(&self, entity: Entity) -> Vec<String>
The clips an animated object’s model offers (empty until its first frame was skinned).
Sourcepub fn set_global(&mut self, key: &str, value: Value)
pub fn set_global(&mut self, key: &str, value: Value)
Stores a value that every script can read with Ctx::global. Lives until the game stops.
Sourcepub fn global_f32(&self, key: &str, default: f32) -> f32
pub fn global_f32(&self, key: &str, default: f32) -> f32
A shared number (integers are converted), or default.
Sourcepub fn global_bool(&self, key: &str, default: bool) -> bool
pub fn global_bool(&self, key: &str, default: bool) -> bool
A shared flag, or default.
Sourcepub fn add_global(&mut self, key: &str, delta: f32) -> f32
pub fn add_global(&mut self, key: &str, delta: f32) -> f32
Adds to a shared number (starting from 0) and returns the new value: ctx.add_global("score", 10.0).
Source§impl Ctx<'_>
Vertex access and deformation (see crate::mesh_deform).
impl Ctx<'_>
Vertex access and deformation (see crate::mesh_deform).
Sourcepub fn make_editable(&mut self, entity: Entity) -> bool
pub fn make_editable(&mut self, entity: Entity) -> bool
Makes the entity’s built-in primitive mesh (primitive:sphere…) editable so its vertices
can be changed from scripts. Returns true when the entity is editable afterwards.
Sourcepub fn editable(&mut self, entity: Entity) -> Option<&mut EditableMesh>
pub fn editable(&mut self, entity: Entity) -> Option<&mut EditableMesh>
The editable mesh of an entity, for deformation: ctx.editable(e)?.twist(Vec3::Y, 30.0).
Source§impl Ctx<'_>
Logging for debugging: everything lands in the editor Console (warnings yellow, errors red).
impl Ctx<'_>
Logging for debugging: everything lands in the editor Console (warnings yellow, errors red).
Sourcepub fn warn(&mut self, message: impl Into<String>)
pub fn warn(&mut self, message: impl Into<String>)
A yellow warning line: ctx.warn("health is below zero").
Sourcepub fn error(&mut self, message: impl Into<String>)
pub fn error(&mut self, message: impl Into<String>)
A red error line. The script keeps running; use it for conditions that should never happen.
Sourcepub fn watch(&mut self, name: &str, value: impl Debug)
pub fn watch(&mut self, name: &str, value: impl Debug)
Logs name = value using Debug: ctx.watch("velocity", ctx.velocity()).
Sourcepub fn watch_every(&mut self, seconds: f32, name: &str, value: impl Debug)
pub fn watch_every(&mut self, seconds: f32, name: &str, value: impl Debug)
Like Ctx::watch but at most once per seconds, so it can sit in update without flooding the Console.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Ctx<'a>
impl<'a> !Send for Ctx<'a>
impl<'a> !Sync for Ctx<'a>
impl<'a> !UnwindSafe for Ctx<'a>
impl<'a> Freeze for Ctx<'a>
impl<'a> Unpin for Ctx<'a>
impl<'a> UnsafeUnpin for Ctx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.