diff options
author | cel <cel@blos.sm> | 2022-07-17 01:37:03 +0100 |
---|---|---|
committer | cel <cel@blos.sm> | 2022-07-17 01:37:03 +0100 |
commit | 8c747cca8d2a357c15937f05eccede3c02043cad (patch) | |
tree | acbf275461fc0122036b89e96f9b3a7222937d13 /godot/scenes/Die.gd | |
parent | 598a36466e76d0c7c16a690a72d4a0e8d7326351 (diff) | |
download | 2022-8c747cca8d2a357c15937f05eccede3c02043cad.tar.gz 2022-8c747cca8d2a357c15937f05eccede3c02043cad.tar.bz2 2022-8c747cca8d2a357c15937f05eccede3c02043cad.zip |
fix mouse aim
Diffstat (limited to '')
-rw-r--r-- | godot/scenes/Die.gd | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd index 5e238f1..1cbb9a0 100644 --- a/godot/scenes/Die.gd +++ b/godot/scenes/Die.gd @@ -1,4 +1,4 @@ -extends Spatial +extends RigidBody var camrot_h = 0 var camrot_v = 0 @@ -8,9 +8,12 @@ var cam_v_max = 90 var sensitivity = 0.5 var dice_is_moving = false var last_frame_position = Vector3(1.0,1.0,1.0) -var dragging = false var mouse_origin = Vector2(0,0) -var dice_launch_force = 0 +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 left_pressed = false # Called when the node enters the scene tree for the first time. func _ready(): @@ -20,30 +23,30 @@ func _ready(): func _input(event): - if event is InputEventMouseMotion: - camrot_h += -event.relative.x * sensitivity - camrot_v += -event.relative.y * sensitivity - - if dice_is_moving == false: - if event is InputEventMouseMotion and dragging: - # While dragging, move the sprite with the mouse. - dice_launch_force = mouse_origin.distance_to(event.global_position) - camrot_v = camrot_v_locked_val - elif event is InputEventMouseButton and event.button_index == BUTTON_LEFT: + + 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 - if not dragging and event.pressed: - dragging = true - # Stop dragging if the button is released. - elif dragging and not event.pressed: - dragging = false - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - - - + left_pressed = true + else: + left_pressed = false + 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 + self.apply_central_impulse(die_launch_force) + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + if event is InputEventMouseMotion: + camrot_h += -event.relative.x * sensitivity + if left_pressed: + camrot_v = camrot_v_locked_val + else: + camrot_v += -event.relative.y * sensitivity - + func _physics_process(delta): camrot_v = clamp(camrot_v, cam_v_min, cam_v_max) @@ -60,7 +63,3 @@ func _physics_process(delta): last_frame_position = Vector3(translation.x, translation.y, translation.x) - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass |