allow lookin g in mouse direction
This commit is contained in:
@@ -23,6 +23,8 @@ var teleported_this_frame: bool = false # Flag to prevent position sync from ove
|
||||
# Input device (for local multiplayer)
|
||||
var input_device: int = -1 # -1 for keyboard, 0+ for gamepad index
|
||||
var virtual_joystick_input: Vector2 = Vector2.ZERO # Virtual joystick input from mobile controls
|
||||
var was_mouse_right_pressed: bool = false # Track previous mouse right button state
|
||||
var was_mouse_left_pressed: bool = false # Track previous mouse left button state
|
||||
|
||||
# Interaction
|
||||
var held_object = null
|
||||
@@ -1251,6 +1253,23 @@ func _get_direction_from_vector(vec: Vector2) -> int:
|
||||
else: # 292.5 to 337.5
|
||||
return Direction.UP_RIGHT
|
||||
|
||||
# Update facing direction from mouse position (called by GameWorld)
|
||||
func _update_facing_from_mouse(mouse_direction: Vector2):
|
||||
# Only update if using keyboard input (not gamepad)
|
||||
if input_device != -1:
|
||||
return
|
||||
|
||||
# Don't update if pushing (locked direction)
|
||||
if is_pushing:
|
||||
return
|
||||
|
||||
var new_direction = _get_direction_from_vector(mouse_direction) as Direction
|
||||
|
||||
# Update direction and cone light rotation if changed
|
||||
if new_direction != current_direction:
|
||||
current_direction = new_direction
|
||||
_update_cone_light_rotation()
|
||||
|
||||
func _set_animation(anim_name: String):
|
||||
if current_animation != anim_name:
|
||||
current_animation = anim_name
|
||||
@@ -1684,6 +1703,7 @@ func _handle_input():
|
||||
last_movement_direction = input_vector.normalized()
|
||||
|
||||
# Update facing direction (except when pushing - locked direction)
|
||||
# Note: Mouse control will override this if mouse is being used
|
||||
var new_direction = current_direction
|
||||
if not is_pushing:
|
||||
new_direction = _get_direction_from_vector(input_vector) as Direction
|
||||
@@ -1774,10 +1794,12 @@ func _handle_interactions():
|
||||
var grab_just_released = false
|
||||
|
||||
if input_device == -1:
|
||||
# Keyboard input
|
||||
grab_button_down = Input.is_action_pressed("grab")
|
||||
grab_just_pressed = Input.is_action_just_pressed("grab")
|
||||
grab_just_released = Input.is_action_just_released("grab")
|
||||
# Keyboard or Mouse input
|
||||
var mouse_right_pressed = Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
|
||||
grab_button_down = Input.is_action_pressed("grab") or mouse_right_pressed
|
||||
grab_just_pressed = Input.is_action_just_pressed("grab") or (mouse_right_pressed and not was_mouse_right_pressed)
|
||||
grab_just_released = Input.is_action_just_released("grab") or (not mouse_right_pressed and was_mouse_right_pressed)
|
||||
was_mouse_right_pressed = mouse_right_pressed
|
||||
|
||||
# DEBUG: Log button states if there's a conflict
|
||||
if grab_just_pressed and grab_just_released:
|
||||
@@ -1907,8 +1929,10 @@ func _handle_interactions():
|
||||
# Handle attack input
|
||||
var attack_just_pressed = false
|
||||
if input_device == -1:
|
||||
# Keyboard
|
||||
attack_just_pressed = Input.is_action_just_pressed("attack")
|
||||
# Keyboard or Mouse
|
||||
var mouse_left_pressed = Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
attack_just_pressed = Input.is_action_just_pressed("attack") or (mouse_left_pressed and not was_mouse_left_pressed)
|
||||
was_mouse_left_pressed = mouse_left_pressed
|
||||
else:
|
||||
# Gamepad (X button)
|
||||
attack_just_pressed = Input.is_joy_button_pressed(input_device, JOY_BUTTON_X)
|
||||
|
||||
Reference in New Issue
Block a user