/target
/.jackdaw
+/.direnv
--- /dev/null
+{
+ "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
+}
--- /dev/null
+{
+ 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
+ ];
+ };
+ }
+ );
+}
struct Grapple {
anchored: bool,
speed: f32,
- force: f32,
+ pull_speed: f32,
+ pull_force: f32,
}
fn spawn_grapple_fire(
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),
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;
}
+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>>,
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(