From d246ed811531bee3abba27fea826bb2191b512eb Mon Sep 17 00:00:00 2001 From: rewin Date: Sun, 24 Mar 2024 22:23:58 +0300 Subject: [PATCH 1/4] Pan orbit camera works --- Cargo.toml | 2 +- crates/editor_ui/src/camera_plugin.rs | 1 + crates/editor_ui/src/game_view.rs | 1 + crates/editor_ui/src/lib.rs | 7 +++---- crates/editor_ui/src/ui_plugin.rs | 4 +++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91ef7590..7cb20c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ bevy_mod_picking = { version = "0.18.1", default-features = false, features = [ "backend_raycast", "selection", ] } -bevy_panorbit_camera = "0.16" +bevy_panorbit_camera = {version = "0.16", default-features = false} bevy-scene-hook = "10" convert_case = "0.6" egui_dock = "0.11" diff --git a/crates/editor_ui/src/camera_plugin.rs b/crates/editor_ui/src/camera_plugin.rs index c154e42e..39163f13 100644 --- a/crates/editor_ui/src/camera_plugin.rs +++ b/crates/editor_ui/src/camera_plugin.rs @@ -57,6 +57,7 @@ pub fn update_pan_orbit( state: Res, ) { for mut pan_orbit in pan_orbit_query.iter_mut() { + info!("Enabled: {}", state.0); pan_orbit.enabled = state.0; } } diff --git a/crates/editor_ui/src/game_view.rs b/crates/editor_ui/src/game_view.rs index add27edf..dc40df37 100644 --- a/crates/editor_ui/src/game_view.rs +++ b/crates/editor_ui/src/game_view.rs @@ -133,6 +133,7 @@ pub fn set_camera_viewport( primary_window: Query<&mut Window, With>, egui_settings: Res, mut cameras: Query<&mut Camera, With>, + ) { let Ok(mut cam) = cameras.get_single_mut() else { return; diff --git a/crates/editor_ui/src/lib.rs b/crates/editor_ui/src/lib.rs index e58eafe9..6ff55f48 100644 --- a/crates/editor_ui/src/lib.rs +++ b/crates/editor_ui/src/lib.rs @@ -347,8 +347,7 @@ pub fn simple_editor_setup(mut commands: Commands) { Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), camera: Camera { - order: isize::MIN, - clear_color: ClearColorConfig::None, + order: 100, ..default() }, ..default() @@ -379,7 +378,7 @@ pub fn game_mode_changed( transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), camera: Camera { // We had too many editor cameras at order 0 - order: -100, + order: 100, ..default() }, ..default() @@ -396,7 +395,7 @@ pub fn game_mode_changed( commands.spawn(( Camera2dBundle { camera: Camera { - order: -100, + order: 100, ..default() }, ..default() diff --git a/crates/editor_ui/src/ui_plugin.rs b/crates/editor_ui/src/ui_plugin.rs index c0d362d0..0e91a630 100644 --- a/crates/editor_ui/src/ui_plugin.rs +++ b/crates/editor_ui/src/ui_plugin.rs @@ -123,7 +123,8 @@ impl Plugin for EditorUiCore { .after(menu_toolbars::bottom_menu), set_camera_viewport, ) - .in_set(UiSystemSet), + .in_set(UiSystemSet) + .before(PanOrbitCameraSystemSet), ); app.add_systems( @@ -431,6 +432,7 @@ pub fn ui_camera_block( }; if let Some(area) = game_view.viewport_rect { if area.contains(pos) { + } else { *state = EditorCameraEnabled(false); } From 8ca2930141187b1faf078a45021cdea9529cff1d Mon Sep 17 00:00:00 2001 From: rewin Date: Sun, 24 Mar 2024 22:53:03 +0300 Subject: [PATCH 2/4] platformer fix --- assets/scenes/platformer.scn.ron | 743 ++++++++++++++++++++++++++ crates/editor_ui/src/camera_plugin.rs | 1 - examples/platformer.rs | 10 +- 3 files changed, 751 insertions(+), 3 deletions(-) create mode 100644 assets/scenes/platformer.scn.ron diff --git a/assets/scenes/platformer.scn.ron b/assets/scenes/platformer.scn.ron new file mode 100644 index 00000000..38819368 --- /dev/null +++ b/assets/scenes/platformer.scn.ron @@ -0,0 +1,743 @@ +( + resources: {}, + entities: { + 8589934609: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: 4.022996, + y: 0.0, + z: 0.0, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 4.322659, + y: 1.0000001, + z: 1.9867467, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Box(( + w: 1.0, + h: 0.1, + d: 1.0, + )), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": FromPrefabMesh, + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Static, + "bevy_xpbd_3d::components::mass_properties::Mass": (8.171806), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.5280972, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 9.428318, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 6.747172, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + }, + ), + 21474836489: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: 25.626577, + y: 0.0, + z: 0.0, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 4.322659, + y: 1.0000001, + z: 1.9867467, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Box(( + w: 1.0, + h: 0.1, + d: 1.0, + )), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": FromPrefabMesh, + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Static, + "bevy_xpbd_3d::components::mass_properties::Mass": (7.77709), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.3979342, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 9.168649, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 6.617009, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + }, + ), + 21474836493: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: -8.806148, + y: 1.5, + z: 0.0, + ), + rotation: ( + x: -0.48451492, + y: -0.4971529, + z: 0.5004074, + w: 0.5173749, + ), + scale: ( + x: 1.000003, + y: 1.0000036, + z: 1.0000024, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Player", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Cube(1.0), + "space_prefab::save::ChildrenPrefab": ([ + 25769803788, + ]), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": Primitive( + pos: ( + x: 0.0, + y: 0.0, + z: 0.0, + ), + rot: ( + x: 0.0, + y: 0.0, + z: 0.0, + ), + primitive: Cuboid(( + x: 1.0, + y: 1.0, + z: 1.0, + )), + ), + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Dynamic, + "bevy_xpbd_3d::components::mass_properties::Mass": (14.000017), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.333338, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 2.333338, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 2.3333383, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + "space_bevy_xpbd_plugin::spatial_query::RayCasterPrefab": ( + direction: ( + x: -1.0, + y: 0.0, + z: 0.0, + ), + origin: ( + x: 0.0, + y: 0.0, + z: 0.0, + ), + ), + "platformer::PlayerController": ( + speed: 10.0, + jump_speed: 100.0, + jumped: false, + ), + }, + ), + 21474836495: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: -9.59452, + y: 5.4386883, + z: 13.7599325, + ), + rotation: ( + x: -0.22447929, + y: -0.09321338, + z: 0.02499185, + w: 0.9696885, + ), + scale: ( + x: 0.99999857, + y: 1.0, + z: 0.99999976, + ), + ), + "bevy_core::name::Name": ( + hash: 3504866713135743650, + name: "Camera3d", + ), + "bevy_render::view::visibility::Visibility": Inherited, + "bevy_render::camera::camera::Camera": ( + viewport: None, + order: 0, + is_active: false, + hdr: false, + msaa_writeback: true, + clear_color: Default, + ), + "bevy_core_pipeline::core_3d::camera_3d::Camera3d": ( + depth_load_op: Clear(0.0), + depth_texture_usages: (16), + screen_space_specular_transmission_steps: 1, + screen_space_specular_transmission_quality: Medium, + ), + "bevy_render::camera::projection::Projection": Perspective(( + fov: 0.7853982, + aspect_ratio: 1.7777778, + near: 0.1, + far: 1000.0, + )), + "space_prefab::component::camera::PlaymodeCamera": (), + "space_prefab::save::ChildrenPrefab": ([ + 47244640267, + ]), + "platformer::FollowCamera": ( + dist: 10.0, + target: ( + entity: 21474836493, + ), + speed: 10.0, + ), + }, + ), + 25769803788: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: -0.019455194, + y: 0.017702103, + z: -0.57863563, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 0.31928456, + y: 0.31928456, + z: 0.31928447, + ), + ), + "bevy_core::name::Name": ( + hash: 6390550647583486133, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Inherited, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Cube(1.0), + }, + ), + 30064771086: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: -2.486157, + y: 0.0, + z: 0.0, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 4.322659, + y: 1.0000001, + z: 1.9867467, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Box(( + w: 1.0, + h: 0.1, + d: 1.0, + )), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": FromPrefabMesh, + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Static, + "bevy_xpbd_3d::components::mass_properties::Mass": (8.171806), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.5280972, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 9.428318, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 6.747172, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + }, + ), + 34359738376: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: -7.6190352, + y: 0.0, + z: 0.0, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 4.322659, + y: 1.0000001, + z: 1.9867467, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Box(( + w: 1.0, + h: 0.1, + d: 1.0, + )), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": FromPrefabMesh, + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Static, + "bevy_xpbd_3d::components::mass_properties::Mass": (8.171806), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.5280972, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 9.428318, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 6.747172, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + }, + ), + 38654705674: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: 12.85639, + y: 0.0, + z: 0.0, + ), + rotation: ( + x: 0.0, + y: 0.0, + z: 0.0, + w: 1.0, + ), + scale: ( + x: 4.322659, + y: 1.0000001, + z: 1.9867467, + ), + ), + "bevy_core::name::Name": ( + hash: 16153353295470017978, + name: "Cube", + ), + "bevy_render::view::visibility::Visibility": Visible, + "space_prefab::component::material::MaterialPrefab": ( + base_color: Rgba( + red: 1.0, + green: 1.0, + blue: 1.0, + alpha: 1.0, + ), + base_color_texture: "", + emissive: Rgba( + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + ), + emissive_texture: "", + perceptual_roughness: 0.5, + metallic: 0.0, + metallic_roughness_texture: "", + reflectance: 0.5, + normal_map_texture: "", + flip_normal_map_y: false, + occlusion_texture: "", + double_sided: false, + unlit: false, + fog_enabled: true, + alpha_mode: Opaque, + depth_bias: 0.0, + depth_map: "", + parallax_depth_scale: 0.1, + parallax_mapping_method: Occlusion, + max_parallax_layer_count: 16.0, + ), + "space_prefab::component::shape::MeshPrimitive3dPrefab": Box(( + w: 1.0, + h: 0.1, + d: 1.0, + )), + "space_bevy_xpbd_plugin::collider::ColliderPrefab": FromPrefabMesh, + "space_bevy_xpbd_plugin::registry::RigidBodyPrefab": Static, + "bevy_xpbd_3d::components::mass_properties::Mass": (8.171806), + "bevy_xpbd_3d::components::Friction": ( + dynamic_coefficient: 0.3, + static_coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::Restitution": ( + coefficient: 0.3, + combine_rule: Average, + ), + "bevy_xpbd_3d::components::mass_properties::Inertia": (( + x_axis: ( + x: 2.5280972, + y: 0.0, + z: 0.0, + ), + y_axis: ( + x: 0.0, + y: 9.428318, + z: 0.0, + ), + z_axis: ( + x: 0.0, + y: 0.0, + z: 6.747172, + ), + )), + "bevy_xpbd_3d::components::mass_properties::CenterOfMass": (( + x: 0.0, + y: 0.0, + z: 0.0, + )), + }, + ), + }, +) \ No newline at end of file diff --git a/crates/editor_ui/src/camera_plugin.rs b/crates/editor_ui/src/camera_plugin.rs index 39163f13..c154e42e 100644 --- a/crates/editor_ui/src/camera_plugin.rs +++ b/crates/editor_ui/src/camera_plugin.rs @@ -57,7 +57,6 @@ pub fn update_pan_orbit( state: Res, ) { for mut pan_orbit in pan_orbit_query.iter_mut() { - info!("Enabled: {}", state.0); pan_orbit.enabled = state.0; } } diff --git a/examples/platformer.rs b/examples/platformer.rs index 3b39e9c3..871d1fad 100644 --- a/examples/platformer.rs +++ b/examples/platformer.rs @@ -36,7 +36,7 @@ fn simple_tab_system(mut ui: NonSendMut) { fn configure_editor(mut load_event: EventWriter) { load_event.send(MenuLoadEvent { - path: "scenes/level_test".to_string(), + path: "scenes/platformer".to_string(), }); } @@ -103,6 +103,7 @@ fn move_player( info!("time of impact: {:?} {:?}", hit.entity, hit.time_of_impact); let frw = transform.forward(); let up = transform.up(); + let right = transform.right(); let mut target_vel = Vector::new(0.0, 0.0, 0.0); if keyboard_input.pressed(KeyCode::KeyW) { @@ -124,19 +125,24 @@ fn move_player( target_vel *= controller.speed; + info!("target_vel: {:?}", target_vel); + //smooth change vel let mut cur_vel = vel.0; cur_vel = vel.0 + (target_vel - cur_vel) * 10.0 * time.delta_seconds(); if keyboard_input.just_pressed(KeyCode::Space) && !controller.jumped { - cur_vel += up * controller.jump_speed / 6.0; + cur_vel += right * controller.jump_speed / 12.0; controller.jumped = true; } if !keyboard_input.just_pressed(KeyCode::Space) { controller.jumped = false; } + vel.0 = cur_vel; + } else { + info!("no hits"); } } } From b6bc840d94524c28457320d416b2e41943021a4c Mon Sep 17 00:00:00 2001 From: rewin Date: Sun, 24 Mar 2024 23:06:18 +0300 Subject: [PATCH 3/4] fxed all examples --- assets/scenes/tile.scn.ron | 137 ------------------------------------- examples/platformer.rs | 8 +-- examples/spawn_prefab.rs | 2 +- 3 files changed, 5 insertions(+), 142 deletions(-) delete mode 100644 assets/scenes/tile.scn.ron diff --git a/assets/scenes/tile.scn.ron b/assets/scenes/tile.scn.ron deleted file mode 100644 index c4fb5aab..00000000 --- a/assets/scenes/tile.scn.ron +++ /dev/null @@ -1,137 +0,0 @@ -( - resources: {}, - entities: { - 4294967297: ( - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 0.0, - y: 0.0, - z: 0.0, - ), - rotation: (x: 0.0, y: 0.0, z: 0.0, w: 1.0), - scale: ( - x: 2.4347973, - y: 0.15754807, - z: 2.4347973, - ), - ), - "bevy_render::view::visibility::Visibility": Inherited, - "space_prefab::component::GltfPrefab": ( - path: "models/cube.glb", - scene: "Scene0", - ), - "space_prefab::save::ChildrenPrefab": ([ - 38654705667, - ]), - }, - ), - 12884901896: ( - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 2.1878946, - y: 0.13795531, - z: -2.1002147, - ), - rotation: (x: 0.0, y: 0.0, z: 0.0, w: 1.0), - scale: ( - x: 0.4790529, - y: 0.36931515, - z: 0.4790529, - ), - ), - "bevy_render::view::visibility::Visibility": Inherited, - "space_prefab::component::GltfPrefab": ( - path: "models/colone.glb", - scene: "Scene0", - ), - "space_prefab::save::ChildrenPrefab": ([ - 9, - 12884901901, - ]), - }, - ), - 12884901918: ( - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: -1.9073787, - y: 0.13795531, - z: -2.0787163, - ), - rotation: (x: 0.0, y: 0.0, z: 0.0, w: 1.0), - scale: ( - x: 0.4790529, - y: 0.36931515, - z: 0.4790529, - ), - ), - "bevy_render::view::visibility::Visibility": Inherited, - "space_prefab::component::GltfPrefab": ( - path: "models/colone.glb", - scene: "Scene0", - ), - "space_prefab::save::ChildrenPrefab": ([ - 32, - 31, - 39, - ]), - }, - ), - 12884901931: ( - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 2.2044797, - y: 0.13796866, - z: 2.0884218, - ), - rotation: (x: 0.0, y: 0.0, z: 0.0, w: 1.0), - scale: ( - x: 0.4790529, - y: 0.36931515, - z: 0.4790529, - ), - ), - "bevy_render::view::visibility::Visibility": Inherited, - "space_prefab::component::GltfPrefab": ( - path: "models/colone.glb", - scene: "Scene0", - ), - "space_prefab::save::ChildrenPrefab": ([ - 45, - 44, - 52, - ]), - }, - ), - 17179869200: ( - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: -1.9329133, - y: 0.13795578, - z: 2.0741177, - ), - rotation: (x: 0.0, y: 0.0, z: 0.0, w: 1.0), - scale: ( - x: 0.4790529, - y: 0.36931515, - z: 0.4790529, - ), - ), - "bevy_render::view::visibility::Visibility": Inherited, - "space_prefab::component::GltfPrefab": ( - path: "models/colone.glb", - scene: "Scene0", - ), - "space_prefab::save::ChildrenPrefab": ([ - 19, - 18, - 26, - ]), - }, - ), - }, -) \ No newline at end of file diff --git a/examples/platformer.rs b/examples/platformer.rs index 871d1fad..93481ee7 100644 --- a/examples/platformer.rs +++ b/examples/platformer.rs @@ -34,10 +34,10 @@ fn simple_tab_system(mut ui: NonSendMut) { ui.label("Hello editor"); } -fn configure_editor(mut load_event: EventWriter) { - load_event.send(MenuLoadEvent { - path: "scenes/platformer".to_string(), - }); +fn configure_editor(mut load_event: EventWriter) { + load_event.send(EditorEvent::Load(EditorPrefabPath::File( + "scenes/platformer.scn.ron".to_string() + ))); } #[derive(Component, Reflect, Clone)] diff --git a/examples/spawn_prefab.rs b/examples/spawn_prefab.rs index 9c551bf8..0a85c598 100644 --- a/examples/spawn_prefab.rs +++ b/examples/spawn_prefab.rs @@ -14,7 +14,7 @@ fn main() { fn setup(mut commands: Commands, _assets: Res) { // prefab loaded by adding PrefabLoader component to any entity (it will be parent of prefab) or with prefab bundle commands - .spawn(PrefabBundle::new("scenes/tile.scn.ron")) + .spawn(PrefabBundle::new("scenes/Scene0.scn.ron")) .insert(Name::new("Prefab")); // light From 41585bfcbf29ac260f1b7cf3383d53a378dea0e7 Mon Sep 17 00:00:00 2001 From: rewin Date: Sun, 24 Mar 2024 23:06:41 +0300 Subject: [PATCH 4/4] fmt --- crates/editor_ui/src/game_view.rs | 1 - crates/editor_ui/src/ui_plugin.rs | 1 - examples/platformer.rs | 5 ++--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/editor_ui/src/game_view.rs b/crates/editor_ui/src/game_view.rs index dc40df37..add27edf 100644 --- a/crates/editor_ui/src/game_view.rs +++ b/crates/editor_ui/src/game_view.rs @@ -133,7 +133,6 @@ pub fn set_camera_viewport( primary_window: Query<&mut Window, With>, egui_settings: Res, mut cameras: Query<&mut Camera, With>, - ) { let Ok(mut cam) = cameras.get_single_mut() else { return; diff --git a/crates/editor_ui/src/ui_plugin.rs b/crates/editor_ui/src/ui_plugin.rs index 0e91a630..e58b4c4f 100644 --- a/crates/editor_ui/src/ui_plugin.rs +++ b/crates/editor_ui/src/ui_plugin.rs @@ -432,7 +432,6 @@ pub fn ui_camera_block( }; if let Some(area) = game_view.viewport_rect { if area.contains(pos) { - } else { *state = EditorCameraEnabled(false); } diff --git a/examples/platformer.rs b/examples/platformer.rs index 93481ee7..e9f1cc15 100644 --- a/examples/platformer.rs +++ b/examples/platformer.rs @@ -36,7 +36,7 @@ fn simple_tab_system(mut ui: NonSendMut) { fn configure_editor(mut load_event: EventWriter) { load_event.send(EditorEvent::Load(EditorPrefabPath::File( - "scenes/platformer.scn.ron".to_string() + "scenes/platformer.scn.ron".to_string(), ))); } @@ -102,7 +102,7 @@ fn move_player( } info!("time of impact: {:?} {:?}", hit.entity, hit.time_of_impact); let frw = transform.forward(); - let up = transform.up(); + // let up = transform.up(); let right = transform.right(); let mut target_vel = Vector::new(0.0, 0.0, 0.0); @@ -139,7 +139,6 @@ fn move_player( controller.jumped = false; } - vel.0 = cur_vel; } else { info!("no hits");