Skip to content

Instantly share code, notes, and snippets.

@winston-yallow
Last active December 11, 2019 22:47
Show Gist options
  • Save winston-yallow/f33bf3c3999664010ea33533ad19688e to your computer and use it in GitHub Desktop.
Save winston-yallow/f33bf3c3999664010ea33533ad19688e to your computer and use it in GitHub Desktop.
Mouse handling for godot emulating a controller axis
extends Node
var mouse_direction_sensitivity := 0.004
var mouse_direction_deadzone := 0.05
var mouse_direction_raw := Vector2()
var direction := Vector2()
func _input(event: InputEvent):
if event is InputEventMouseMotion:
mouse_direction_raw += event.relative * mouse_direction_sensitivity
if mouse_direction_raw.length() > 1:
mouse_direction_raw = mouse_direction_raw.normalized()
func _process(delta: float):
if mouse_direction_raw.length() > mouse_direction_deadzone:
direction = mouse_direction_raw
else:
direction *= 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment