From 001ce7e98c125addfbb6d3c7cc953c1de2234a3f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 3 Jan 2021 17:16:39 +0100 Subject: [PATCH] Implement basic jumping --- src/player.rs | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/player.rs b/src/player.rs index bad44e4..7ffc50f 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,13 +1,10 @@ -use bevy::{ - input::mouse::MouseMotion, - prelude::*, -}; +use bevy::{input::mouse::MouseMotion, prelude::*}; use bevy_rapier3d::{ na::{clamp, wrap, Matrix3x1}, - physics::RigidBodyHandleComponent, + physics::{ColliderHandleComponent, RigidBodyHandleComponent}, rapier::{ dynamics::{RigidBody, RigidBodyBuilder, RigidBodySet}, - geometry::ColliderBuilder, + geometry::{ColliderBuilder, NarrowPhase}, }, }; use std::f32::consts::{FRAC_PI_2, PI}; @@ -73,16 +70,40 @@ fn init_player(commands: &mut Commands) { }); } +// TODO: this is incomplete, currently just checks that the player is touching anything +fn is_on_ground( + narrow_phase: &Res, + collider_handle: &ColliderHandleComponent, +) -> bool { + if let Some(n1) = narrow_phase.contacts_with(collider_handle.handle()) { + for _n2 in n1 { + return true; + } + } + return false; +} + fn player_movement_system( time: Res