]> Untitled Git - axy/ft/rogue-mmo.git/commitdiff
Grapple improvements and nix master
authorAxy <gilliardmarthey.axel@gmail.com>
Sat, 28 Nov 2026 21:03:31 +0000 (22:03 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Sat, 28 Nov 2026 21:03:31 +0000 (22:03 +0100)
.envrc [new file with mode: 0644]
.gitignore
flake.lock [new file with mode: 0644]
flake.nix [new file with mode: 0644]
src/lib.rs

diff --git a/.envrc b/.envrc
new file mode 100644 (file)
index 0000000..3550a30
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
index bf0b126e8e37fb7086c14d3f998b1536b0bbb05e..f10e9cbe9a446e87155eae6c060b274a44bf1e40 100644 (file)
@@ -1,2 +1,3 @@
 /target
 /.jackdaw
 /target
 /.jackdaw
+/.direnv
diff --git a/flake.lock b/flake.lock
new file mode 100644 (file)
index 0000000..4c61441
--- /dev/null
@@ -0,0 +1,96 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1794427683,
+        "narHash": "sha256-o7ey9gEilsxaifqJWnBDlYSKbNWYQYtKwDyXeZU2kaU=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "cd489559845d81f673a12885576016c65cbe9363",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1795761588,
+        "narHash": "sha256-lyvlcjA/bJySrgwKiEoIYFNkDJM6aOck6/9gGRm9He4=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "78cc855faf4382e44b781c23bf9f456b924ef0e2",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixpkgs_2": {
+      "locked": {
+        "lastModified": 1744536153,
+        "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs",
+        "rust-overlay": "rust-overlay"
+      }
+    },
+    "rust-overlay": {
+      "inputs": {
+        "nixpkgs": "nixpkgs_2"
+      },
+      "locked": {
+        "lastModified": 1795860178,
+        "narHash": "sha256-ohgonNy3+RvquNpQVDOiI7lanO246mw1qZ/RaBIXUFE=",
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "rev": "f88aa8dea8f4136a0897fd7baddb3a07481f29f6",
+        "type": "github"
+      },
+      "original": {
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "type": "github"
+      }
+    },
+    "systems": {
+      "locked": {
+        "lastModified": 1791244623,
+        "narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=",
+        "owner": "nix-systems",
+        "repo": "default",
+        "rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-systems",
+        "repo": "default",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644 (file)
index 0000000..4274244
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,64 @@
+{
+  description = "bevy flake";
+
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+    rust-overlay.url = "github:oxalica/rust-overlay";
+    flake-utils.url = "github:numtide/flake-utils";
+  };
+
+  outputs =
+    {
+      nixpkgs,
+      rust-overlay,
+      flake-utils,
+      ...
+    }:
+    flake-utils.lib.eachDefaultSystem (
+      system:
+      let
+        overlays = [ (import rust-overlay) ];
+        pkgs = import nixpkgs {
+          inherit system overlays;
+        };
+      in
+      {
+        devShells.default =
+          with pkgs;
+          mkShell {
+            buildInputs =
+              [
+                # Rust dependencies
+                (rust-bin.stable.latest.default.override { extensions = [ "rust-src" ]; })
+                pkg-config
+              ]
+              ++ lib.optionals (lib.strings.hasInfix "linux" system) [
+                # for Linux
+                # Audio (Linux only)
+                alsa-lib
+                # Cross Platform 3D Graphics API
+                vulkan-loader
+                # For debugging around vulkan
+                vulkan-tools
+                # Other dependencies
+                libudev-zero
+                libx11
+                libxcursor
+                libxi
+                libxrandr
+                libxkbcommon
+                wayland
+              ];
+            RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
+            LD_LIBRARY_PATH = lib.makeLibraryPath [
+              vulkan-loader
+              libx11
+              libxi
+              libxcursor
+              libxkbcommon
+              wayland
+            ];
+          };
+      }
+    );
+}
index a9cfd42ddc64d4c38262bf67d496f3c2b3fd62a6..a636e94c7346a64da946f658dc2de14122559aa6 100644 (file)
@@ -137,7 +137,8 @@ struct GrappleFire;
 struct Grapple {
     anchored: bool,
     speed: f32,
 struct Grapple {
     anchored: bool,
     speed: f32,
-    force: f32,
+    pull_speed: f32,
+    pull_force: f32,
 }
 
 fn spawn_grapple_fire(
 }
 
 fn spawn_grapple_fire(
@@ -150,7 +151,8 @@ fn spawn_grapple_fire(
         Grapple {
             anchored: false,
             speed: 45.0,
         Grapple {
             anchored: false,
             speed: 45.0,
-            force: 60.0,
+            pull_speed: 15.0,
+            pull_force: 40.0,
         },
         player.with_translation(player.translation + player.rotation * Vec3::NEG_Z * 3.0),
         Collider::sphere(0.2),
         },
         player.with_translation(player.translation + player.rotation * Vec3::NEG_Z * 3.0),
         Collider::sphere(0.2),
@@ -202,10 +204,19 @@ fn move_grapple_collide(
     let hit_transform = positions.get(hit.entity).unwrap();
     let world_offset = hit.point1 - hit_transform.translation();
     **transform = Transform::from_translation(hit_transform.rotation().inverse() * world_offset);
     let hit_transform = positions.get(hit.entity).unwrap();
     let world_offset = hit.point1 - hit_transform.translation();
     **transform = Transform::from_translation(hit_transform.rotation().inverse() * world_offset);
-    commands.entity(entity).insert(ChildOf(hit.entity));
+    commands.entity(entity).insert((ChildOf(hit.entity),));
     grapple.anchored = true;
 }
 
     grapple.anchored = true;
 }
 
+fn extract_direction_component(vec: Vec3, direction: Vec3) -> Vec3 {
+    let dot = vec.dot(direction);
+    direction * dot.max(0.0)
+}
+
+fn remove_direction_component(vec: Vec3, direction: Vec3) -> Vec3 {
+    vec - extract_direction_component(vec, direction)
+}
+
 fn move_player_to_grapple(
     grapple: Single<(&Grapple, &GlobalTransform)>,
     mut player: Single<(&mut LinearVelocity, &GlobalTransform), With<Player>>,
 fn move_player_to_grapple(
     grapple: Single<(&Grapple, &GlobalTransform)>,
     mut player: Single<(&mut LinearVelocity, &GlobalTransform), With<Player>>,
@@ -215,7 +226,20 @@ fn move_player_to_grapple(
         return;
     }
     let delta = grapple.1.translation() - player.1.translation();
         return;
     }
     let delta = grapple.1.translation() - player.1.translation();
-    (player.0).0 += delta.normalize() * grapple.0.force * time.delta_secs();
+    let direction = delta.normalize();
+    (player.0).0 = remove_direction_component((player.0).0, -direction);
+    let terminal_damp = (1.0
+        - extract_direction_component((player.0).0, direction).length() / grapple.0.pull_speed)
+        .clamp(0.0, 1.0);
+    let closeness_damp = (player
+        .1
+        .translation()
+        .distance(grapple.1.translation())
+        .clamp(1.0, 3.0)
+        - 1.0)
+        * 0.5;
+    (player.0).0 +=
+        direction * grapple.0.pull_force * closeness_damp * terminal_damp * time.delta_secs();
 }
 
 fn despawn_grapple_once_reached(
 }
 
 fn despawn_grapple_once_reached(