Skip to content

WASDWithMouseLogic ​

Inherits: ControllerLogic < Resource

WASD movement with mouse for rotation and targeting WASD: Move character (relative to the character or to the camera: movement_basis) Right-drag: Rotate character (CHARACTER basis) / orbit the camera (CAMERA basis) Left-click: Select/target (left-drag orbits the camera) Right-click: Attack/interact

Properties ​

SecondaryActionTriggersecondary_action_triggerSecondaryActionTrigger.PRESS
boolauto_face_overrides_mouse_looktrue
ControllerLogic.MovementBasismovement_basisControllerLogic.MovementBasis.CHARACTER
boolsnap_body_to_camera_on_lookfalse
floatdirection_stability_threshold0.7
boolallow_lock_ontrue
boolallow_lock_on_switchtrue
floattarget_lock_rotation_speed10.0
boolauto_face_on_attacktrue
boolenable_keyboard_interacttrue
boolfire_aimed_attack_with_primarytrue

Variables ​

Vector2input_vectorVector2.ZERO
Vector2last_movement_directionVector2.ZERO
Variantpending_interaction_targetnull

Methods ​

voidsetup( pc: PlayerController )
voidcleanup()
voidhandle_input_event( event: InputEvent )
voidprocess_input( delta: float )
Playerget_current_player()
Array[Entity]get_selected_units()
boolcan_handle_direct_movement()
boolcan_handle_keyboard_interact()
voidselect_single_player( player: Entity )
Stringget_type_display_name()
boolhandle_interact_input()
boolhandle_esc_input()
ControllerLogic.MovementBasisget_movement_basis()
Array[LookBinding]get_look_bindings()
voidhandle_look( kind: LookBinding.Kind, delta_rad: Vector2 )
voidon_look_state( kind: LookBinding.Kind, active: bool )
voidon_click_completed( button_index: int, position: Vector2 )
voidprocess_target_lock( delta: float )
voidon_target_lock_changed( is_locked: bool, target: Variant )

Property descriptions ​

WASD Movement

SecondaryActionTrigger secondary_action_trigger = SecondaryActionTrigger.PRESS ​

When the right-click action fires. RELEASE_WITHOUT_DRAG separates "click to act" from "drag to look" (mouse-look then starts only after the pointer moves GameplayConfig.look_drag_threshold pixels).

bool auto_face_overrides_mouse_look = true ​

What happens when an ability/effect asks the player to auto-face a target while right-mouse look is held. true = the auto-face turn wins (mouse turning pauses until it finishes; the original behaviour). false = mouse-look wins (auto-face requests are ignored while held, so the ability fires the way the player is facing).

ControllerLogic.MovementBasis movement_basis = ControllerLogic.MovementBasis.CHARACTER ​

What WASD is relative to. CHARACTER: W moves the way the character faces and right-drag turns the body (the camera locks behind it). CAMERA: W moves away from the camera; right- and left-drag orbit the camera; the body turns to face the way it moves (and faces a locked target).

bool snap_body_to_camera_on_look = false ​

CHARACTER basis only. When right-drag mouse-look starts while the camera has been orbited away from the body: true = the body snaps to where the camera is facing (the camera does not move); false = the camera eases back behind the body (the body does not move until you drag).

float direction_stability_threshold = 0.7 ​

Direction stability threshold (prevents animation flickering)

WASD Targeting

bool allow_lock_on = true ​

Lock-on targeting system

bool allow_lock_on_switch = true ​

Switch targets while locked on

float target_lock_rotation_speed = 10.0 ​

Target lock rotation speed (radians per second)

Combat

bool auto_face_on_attack = true ​

Auto-face target when attacking

Interaction

bool enable_keyboard_interact = true ​

Enable keyboard interaction (E key)

bool fire_aimed_attack_with_primary = true ​

Hold the primary button while the mouse is captured (looking around) to fire the basic attack of an aimed weapon (a bow, a gun) at what the crosshair aims at; a basic attack that waits for the release (a drawn bow) is loosed when the button is let go. With a target locked on, the auto attack already fires at it.

Variable descriptions ​

Vector2 input_vector = Vector2.ZERO ​

Runtime state (not exported)

Vector2 last_movement_direction = Vector2.ZERO ​

The last direction the keys asked for.

Variant pending_interaction_target = null ​

The thing the player is walking to use.

Method descriptions ​

void setup( pc: PlayerController ) ​

Sets the logic up when it becomes the one in use.

void cleanup() ​

Lets go of what the logic holds when it is replaced.

void handle_input_event( event: InputEvent ) ​

Handles one input event (a click, a key).

void process_input( delta: float ) ​

Handles the input of one frame.

Player get_current_player() ​

The player the logic controls now.

Array[Entity] get_selected_units() ​

The entities the player has selected.

bool can_handle_direct_movement() ​

Does the logic move the player directly (with keys)?

bool can_handle_keyboard_interact() ​

Can the player use objects with the interact key?

void select_single_player( player: Entity ) ​

Selects one player.

String get_type_display_name() ​

The name of the logic in the editor.

bool handle_interact_input() ​

Handle keyboard interaction (E key) - uses Area3D detection from Player

bool handle_esc_input() ​

Handles the Escape key. True when the logic used it.

ControllerLogic.MovementBasis get_movement_basis() ​

What the movement keys are relative to (the character or the camera).

Array[LookBinding] get_look_bindings() ​

The mouse buttons that turn the view or the character for this logic.

void handle_look( kind: LookBinding.Kind, delta_rad: Vector2 ) ​

Turns the view or the character by the mouse movement.

void on_look_state( kind: LookBinding.Kind, active: bool ) ​

Called when a look button is pressed or released.

void on_click_completed( button_index: int, position: Vector2 ) ​

Called when a click ends (the button and the place on the screen).

void process_target_lock( delta: float ) ​

Process target lock - rotate character to face locked target

void on_target_lock_changed( is_locked: bool, target: Variant ) ​

Called when target lock state changes