From 01a94832a17bcc34a6208a9896a97fa82b37975b Mon Sep 17 00:00:00 2001 From: Top1055 <123alexfeetham@gmail.com> Date: Sun, 28 Dec 2025 11:43:24 +0000 Subject: [PATCH] implemented right-click movement, up to speed with original c++ code --- src/main.rs | 100 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0aac0ae..c606b6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,19 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) - .add_systems(Update, rotate_cube) + .add_systems(Update, (handle_click, move_to_target)) .run(); } #[derive(Component)] -struct RotatingCube { - rotation_speed: f32, +struct Player { + move_speed: f32, + height_offset: f32, +} + +#[derive(Component)] +struct MoveTarget { + position: Vec3, } fn setup( @@ -29,8 +35,12 @@ fn setup( Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))), MeshMaterial3d(materials.add(Color::srgb(1.0, 0.0, 0.0))), Transform::from_xyz(0.0, 1.0, 0.0), - RotatingCube { - rotation_speed: 2.0, + Player { + move_speed: 10.0, + height_offset: 1.0, + }, + MoveTarget { + position: Vec3::new(0.0, 0.0, 0.0), }, )); @@ -41,7 +51,7 @@ fn setup( shadows_enabled: true, ..default() }, - Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), + Transform::from_xyz(0.0, 10.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), )); // Plane @@ -51,27 +61,67 @@ fn setup( )); } -fn rotate_cube( - mut query: Query< - ( - &mut Transform, - &RotatingCube, - &MeshMaterial3d, - ), - Without, - >, - time: Res