aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar David <david003@gmx.net>2022-07-16 15:47:20 +0200
committerLibravatar David <david003@gmx.net>2022-07-16 15:47:20 +0200
commitea7596edf57149b3c3f84378276c9d0558aed050 (patch)
tree591680281666791cf24c116d6fef9559bb201bca
parent635cfebff3ec0ce5b74ac728a5655339755efe39 (diff)
download2022-ea7596edf57149b3c3f84378276c9d0558aed050.tar.gz
2022-ea7596edf57149b3c3f84378276c9d0558aed050.tar.bz2
2022-ea7596edf57149b3c3f84378276c9d0558aed050.zip
better stopping detection
Diffstat (limited to '')
-rw-r--r--godot/scenes/objects/Player.tscn4
-rwxr-xr-xlib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.sobin28904944 -> 29349872 bytes
-rw-r--r--rust/src/basic_die.rs43
3 files changed, 33 insertions, 14 deletions
diff --git a/godot/scenes/objects/Player.tscn b/godot/scenes/objects/Player.tscn
index f8a3fba..9730147 100644
--- a/godot/scenes/objects/Player.tscn
+++ b/godot/scenes/objects/Player.tscn
@@ -6,12 +6,12 @@
[node name="PlayerRoot" type="Spatial"]
script = ExtResource( 3 )
-camera/camera_clamp = Vector2( 0, -2 )
+camera/camera_clamp = Vector2( 0, -1.3 )
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
+input/shoot_sensitivity = 0.1
[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
index 4b82952..97b6350 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
Binary files differ
diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs
index ffd3bff..ab53720 100644
--- a/rust/src/basic_die.rs
+++ b/rust/src/basic_die.rs
@@ -25,6 +25,8 @@ pub struct BasicDie {
up_angle: f32,
#[property(path="shooting/stopping_velocity")]
stopping_velocity: f32,
+ #[property(path="shooting/stopping_min_milliseconds")]
+ stopping_min_ms: i64,
#[property(path="input/camera_mouse_sensitivity")]
mouse_sensitivity: Vector2,
#[property(path="input/shoot_sensitivity")]
@@ -32,6 +34,7 @@ pub struct BasicDie {
input_state: InputState,
current_force: f32,
+ last_shot_time: i64,
action_shooting: String,
@@ -56,11 +59,13 @@ impl BasicDie {
max_force: 0.0,
up_angle: 5.0,
stopping_velocity: 0.0,
+ stopping_min_ms: 1000,
mouse_sensitivity: Vector2 { x: 1.0, y: 1.0 },
shoot_sensitivity: 1.0,
input_state: InputState::Default,
current_force: 0.0,
+ last_shot_time: 0,
action_shooting: String::from("mouse_btn_left"),
@@ -75,10 +80,12 @@ impl BasicDie {
#[export]
unsafe fn _ready(&mut self, owner: &Spatial) {
- Input::godot_singleton().set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
+ Input::godot_singleton().set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
owner.set_physics_process(true);
+ self.last_shot_time = OS::godot_singleton().get_ticks_msec();
+
let search_node = | parent: &SpatialRef, name: String | {
let parent_node = match parent {
Some(node) => node.assume_safe().as_ref(),
@@ -114,23 +121,33 @@ impl BasicDie {
#[export]
unsafe fn _physics_process(&mut self, _owner: &Spatial, _delta: f64) {
+
+ let die = match self.node_die {
+ None => { godot_warn!("No W8 assigned."); return; },
+ Some(node) => match node.assume_safe().cast::<RigidBody>() {
+ None => { godot_warn!("W8 is not a RigidBody."); return; },
+ Some(rb) => rb
+ }
+ };
+
+ // let the cam follow the die
+ match self.node_camera_root {
+ None => { godot_warn!("No W8 assigned."); },
+ Some(cam) => {
+ cam.assume_safe().set_translation(die.translation());
+ }
+ }
// detect if the die stops moving
- if matches!(self.input_state, InputState::Moving) {
- // get the current velocity
- let current_vel = match self.node_die {
- None => { godot_warn!("No W8 assigned."); 0.0 },
- Some(node) =>
- match node.assume_safe().cast::<RigidBody>() {
- None => { godot_warn!("W8 is not a RigidBody."); 0.0 },
- Some(rb) => rb.linear_velocity().length()
- }
- };
+ let delta_ms = OS::godot_singleton().get_ticks_msec() - self.last_shot_time;
+ if matches!(self.input_state, InputState::Moving)
+ && (delta_ms > self.stopping_min_ms) {
// check if the velocity is less than the threshold and change input state in that case
+ let current_vel = die.linear_velocity().length();
if current_vel <= self.stopping_velocity {
self.input_state = InputState::Default;
- godot_print!("Die stopped moving");
+ godot_print!("Die stopped moving at velocity {} after {} ms", current_vel, delta_ms);
}
};
}
@@ -297,5 +314,7 @@ impl BasicDie {
// actually add the force
die.apply_impulse(die.transform().origin, impulse_dir);
+
+ self.last_shot_time = OS::godot_singleton().get_ticks_msec();
}
}