Last active
December 11, 2019 22:47
-
-
Save winston-yallow/f33bf3c3999664010ea33533ad19688e to your computer and use it in GitHub Desktop.
Mouse handling for godot emulating a controller axis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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