diff options
author | David <david003@gmx.net> | 2022-07-16 15:12:11 +0200 |
---|---|---|
committer | David <david003@gmx.net> | 2022-07-16 15:12:11 +0200 |
commit | 635cfebff3ec0ce5b74ac728a5655339755efe39 (patch) | |
tree | 6ae3def84f22a3ce48e61804b13edb66a37b79c9 /rust/src/basic_die.rs | |
parent | bb721621d661ab4e068a589a853c2420b7ac6566 (diff) | |
download | 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.tar.gz 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.tar.bz2 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.zip |
better mouse handling. correct impulse
Diffstat (limited to 'rust/src/basic_die.rs')
-rw-r--r-- | rust/src/basic_die.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs index 0b028b8..ffd3bff 100644 --- a/rust/src/basic_die.rs +++ b/rust/src/basic_die.rs @@ -75,7 +75,8 @@ impl BasicDie { #[export] unsafe fn _ready(&mut self, owner: &Spatial) { - godot_print!("Player starting"); + Input::godot_singleton().set_mouse_mode(Input::MOUSE_MODE_CAPTURED); + owner.set_physics_process(true); let search_node = | parent: &SpatialRef, name: String | { @@ -125,11 +126,11 @@ impl BasicDie { Some(rb) => rb.linear_velocity().length() } }; - godot_print!("current velocity: {}", current_vel); // check if the velocity is less than the threshold and change input state in that case if current_vel <= self.stopping_velocity { self.input_state = InputState::Default; + godot_print!("Die stopped moving"); } }; } @@ -159,6 +160,16 @@ impl BasicDie { }, _ => {} } + + let key_event = save_event.cast::<InputEventKey>(); + match key_event { + Some(key_event) => { + if key_event.scancode() == GlobalConstants::KEY_ESCAPE { + Input::godot_singleton().set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + } + }, + _ => {} + } } /// this input method will be called when looking around, before taking a shot @@ -198,7 +209,7 @@ impl BasicDie { let mouse_event = save_event.cast::<InputEventMouseMotion>(); // get the input as mouse input match mouse_event { Some(motion_event) => { - let y_mov = motion_event.relative().y * self.mouse_sensitivity.y; + let y_mov = motion_event.relative().y * self.shoot_sensitivity; self.current_force = match self.current_force + y_mov { x if x < 0.0 => 0.0, x if x > self.max_force => self.max_force, @@ -266,7 +277,7 @@ impl BasicDie { None => { godot_warn!("No camera assigned!"); return; }, Some(cam) => { // get the forward vector of the camera setting the up angle to the defined value in the editor - let mut forward_vector = cam.assume_safe().global_transform().basis.c(); + let mut forward_vector = -cam.assume_safe().global_transform().basis.c(); forward_vector.y = self.up_angle; // calculate the impulse force |