wasm-module: add get_speed

This commit is contained in:
2026-03-06 08:33:01 -08:00
parent 01916e0682
commit 6fbeba94ae
4 changed files with 16 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -1700,6 +1700,7 @@ dependencies = [
name = "strafesnet_roblox_bot_player_wasm_module"
version = "0.1.0"
dependencies = [
"glam",
"strafesnet_common",
"strafesnet_graphics",
"strafesnet_roblox_bot_file",

View File

@@ -131,6 +131,12 @@ impl PlaybackHead{
(p+CompleteBot::CAMERA_OFFSET,angles.yx())
}
pub fn get_velocity(&self,bot:&CompleteBot,time:SessionTime)->glam::Vec3{
let interp=self.interpolate_output(bot,time);
let v0=vector3_to_glam(&interp.event0.velocity);
let v1=vector3_to_glam(&interp.event1.velocity);
v0.lerp(v1,interp.t)
}
}
struct InterpolateOutput<'a>{

View File

@@ -11,6 +11,7 @@ default = []
webgl = ["wgpu/webgl"]
[dependencies]
glam.workspace = true
strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" }
strafesnet_common.workspace = true
strafesnet_graphics.workspace = true

View File

@@ -171,4 +171,12 @@ impl PlaybackHead{
pub fn get_fov_slope_y(&self)->f64{
self.head.state().get_fov_y()
}
#[wasm_bindgen]
pub fn get_speed(&self,bot:&CompleteBot,time:f64)->f32{
let time=time::from_float(time).unwrap();
let velocity=self.head.get_velocity(&bot.bot,time);
use glam::Vec3Swizzles;
velocity.xz().length()
}
}