From 824455501b8063666c8c84831b67dfd4548a2fab Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Thu, 3 Feb 2022 13:52:23 +0100 Subject: [PATCH] update strafe action if keyboard is used in same time with mouse left button --- player/player.gd | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/player/player.gd b/player/player.gd index 1a9df10..e7fd765 100644 --- a/player/player.gd +++ b/player/player.gd @@ -42,7 +42,7 @@ func _input(event): if Input.is_mouse_button_pressed( 2 ): if event is InputEventMouseMotion: camera_rotate_y -= event.relative.x *0.01 - if camera_rotate_y >= PI: + if camera_rotate_y > PI: camera_rotate_y -= TWO_PI elif camera_rotate_y <= -PI: camera_rotate_y += TWO_PI @@ -55,6 +55,8 @@ func _input(event): func _physics_process(delta): + var input_dir: Vector2 + # Add the gravity. if not is_on_floor(): motion_velocity.y -= gravity * delta @@ -63,11 +65,14 @@ func _physics_process(delta): if Input.is_action_just_pressed("ui_accept") and is_on_floor(): motion_velocity.y = JUMP_FORCE - if not Input.is_action_pressed( "ui_strafe" ): + # Get the input direction and handle the movement/deceleration. + if Input.is_action_pressed("ui_strafe"): + input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up") + else: # if not Input.is_action_pressed( "ui_strafe" ): var y = 0 - if Input.is_action_pressed("ui_right"): + if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_strafe_right"): y -= 1 - if Input.is_action_pressed("ui_left"): + if Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_strafe_left"): y += 1 if y != 0: var dt = y * delta * speed_rotate_1sec @@ -77,14 +82,8 @@ func _physics_process(delta): elif camera_rotate_y <= -PI: camera_rotate_y += TWO_PI $camera_root/horizontal_root.rotate_y( dt ) - - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var input_dir: Vector2 - if Input.is_action_pressed("ui_strafe"): - input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up") - else: input_dir = Input.get_vector("ui_strafe_right", "ui_strafe_left", "ui_down", "ui_up") + var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction: motion_velocity.x = direction.x * SPEED