From fab6add55efe3fe00c8eec75d71514bd4085ba6e Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 17 Jul 2022 04:17:33 +0100 Subject: fix mouse aim AGAIN --- godot/scenes/Die.gd | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'godot/scenes/Die.gd') diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd index 9341bc1..558af14 100644 --- a/godot/scenes/Die.gd +++ b/godot/scenes/Die.gd @@ -15,6 +15,7 @@ var die_launch_force_magnitude = 0 var die_launch_force_direction = Vector3(0,0,0) var die_launch_force = Vector3(0,0,0) var die_launch_force_multiplier = 0.05 +var die_launch_force_magnitude_max = 500 var left_pressed = false var mat @@ -31,6 +32,8 @@ func _ready(): _game = get_node("/root/Game") mat = get_physics_material_override() previous_bounciness = mat.get_bounce() + $PowerUI/PowerBar.hide() + $PowerUI/PowerBar.max_value = die_launch_force_magnitude_max func _input(event): @@ -50,23 +53,30 @@ func _input(event): if event is InputEventMouseButton and dice_is_moving == false: if event.is_pressed() and left_pressed == false: - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - mouse_origin = event.global_position - camrot_v_locked_val = camrot_v left_pressed = true + camrot_v_locked_val = camrot_v + #Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + #mouse_origin = event.global_position + die_launch_force_magnitude = 0 + $PowerUI/PowerBar.show() + else: left_pressed = false - die_launch_force_magnitude = -(mouse_origin.y - event.global_position.y) + #die_launch_force_magnitude = -(mouse_origin.y - event.global_position.y) die_launch_force_direction = $CamRoot/Horizontal/Vertical/Camera.get_global_transform().basis die_launch_force_direction = -die_launch_force_direction.z - die_launch_force = die_launch_force_direction * die_launch_force_magnitude * die_launch_force_multiplier + die_launch_force = die_launch_force_direction * clamp(die_launch_force_magnitude, 0, die_launch_force_magnitude_max) * die_launch_force_multiplier self.apply_central_impulse(die_launch_force) - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + $PowerUI/PowerBar.hide() + #Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + # add one to counter if event is InputEventMouseMotion: camrot_h += -event.relative.x * sensitivity if left_pressed: camrot_v = camrot_v_locked_val + die_launch_force_magnitude += event.relative.y * sensitivity + $PowerUI/PowerBar.value = die_launch_force_magnitude else: camrot_v += -event.relative.y * sensitivity @@ -80,15 +90,13 @@ func _physics_process(delta): $CamRoot.translation.y = translation.y + 5 $CamRoot.translation.z = translation.z - if last_frame_position != Vector3(translation.x, translation.y, translation.x): - dice_is_moving = true - else: + if dice_is_moving == true and angular_velocity.length() < 0.01 and linear_velocity.length() < 0.01: dice_is_moving = false + get_upwards_side() + elif dice_is_moving == false and angular_velocity.length() >= 0.01 and linear_velocity.length() >= 0.01: + dice_is_moving = true - if angular_velocity.length() == 0: - get_upwards_side() - - last_frame_position = Vector3(translation.x, translation.y, translation.x) + # Called every frame. 'delta' is the elapsed time since the previous frame. -- cgit