update strafe action if keyboard is used in same time with mouse left button

This commit is contained in:
AleaJactaEst 2022-02-03 13:52:23 +01:00
parent 2eb384b920
commit 824455501b

View file

@ -42,7 +42,7 @@ func _input(event):
if Input.is_mouse_button_pressed( 2 ): if Input.is_mouse_button_pressed( 2 ):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
camera_rotate_y -= event.relative.x *0.01 camera_rotate_y -= event.relative.x *0.01
if camera_rotate_y >= PI: if camera_rotate_y > PI:
camera_rotate_y -= TWO_PI camera_rotate_y -= TWO_PI
elif camera_rotate_y <= -PI: elif camera_rotate_y <= -PI:
camera_rotate_y += TWO_PI camera_rotate_y += TWO_PI
@ -55,6 +55,8 @@ func _input(event):
func _physics_process(delta): func _physics_process(delta):
var input_dir: Vector2
# Add the gravity. # Add the gravity.
if not is_on_floor(): if not is_on_floor():
motion_velocity.y -= gravity * delta 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(): if Input.is_action_just_pressed("ui_accept") and is_on_floor():
motion_velocity.y = JUMP_FORCE 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 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 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 y += 1
if y != 0: if y != 0:
var dt = y * delta * speed_rotate_1sec var dt = y * delta * speed_rotate_1sec
@ -77,14 +82,8 @@ func _physics_process(delta):
elif camera_rotate_y <= -PI: elif camera_rotate_y <= -PI:
camera_rotate_y += TWO_PI camera_rotate_y += TWO_PI
$camera_root/horizontal_root.rotate_y( dt ) $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") 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() var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction: if direction:
motion_velocity.x = direction.x * SPEED motion_velocity.x = direction.x * SPEED