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 | |
parent | bb721621d661ab4e068a589a853c2420b7ac6566 (diff) | |
download | 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.tar.gz 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.tar.bz2 2022-635cfebff3ec0ce5b74ac728a5655339755efe39.zip |
better mouse handling. correct impulse
-rw-r--r-- | godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn | 2 | ||||
-rw-r--r-- | godot/scenes/objects/Player.tscn | 6 | ||||
-rwxr-xr-x | lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so | bin | 28423064 -> 28904944 bytes | |||
-rw-r--r-- | rust/src/basic_die.rs | 19 |
4 files changed, 21 insertions, 6 deletions
diff --git a/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn b/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn index 688f1c7..d23236b 100644 --- a/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn +++ b/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn @@ -28,5 +28,3 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 40, -1, -20 ) transform = Transform( 0.766044, 0, 0.642788, 0, 2, 0, -0.642788, 0, 0.766044, 19.47, 0, -14 ) [node name="PlayerRoot" parent="." instance=ExtResource( 3 )] -input/camera_mouse_sensitivity = Vector2( 0.014, 0.01 ) -input/shoot_sensitivity = 0.041 diff --git a/godot/scenes/objects/Player.tscn b/godot/scenes/objects/Player.tscn index 0d162f4..f8a3fba 100644 --- a/godot/scenes/objects/Player.tscn +++ b/godot/scenes/objects/Player.tscn @@ -6,6 +6,12 @@ [node name="PlayerRoot" type="Spatial"] script = ExtResource( 3 ) +camera/camera_clamp = Vector2( 0, -2 ) +shooting/max_force = 30.0 +shooting/up_angle = 1.0 +shooting/stopping_velocity = 0.003 +input/camera_mouse_sensitivity = Vector2( 0.003, 0.002 ) +input/shoot_sensitivity = 0.3 [node name="W8" parent="." instance=ExtResource( 1 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0 ) diff --git a/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so b/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so Binary files differindex d878485..4b82952 100755 --- a/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so +++ b/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so 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 |