Last active
September 13, 2019 19:30
-
-
Save willnationsdev/8c277b089e1a3fa89382ec875a923b0a to your computer and use it in GitHub Desktop.
animation on input sample
This file contains 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 KinematicBody | |
var rotation_x_delta = 0.0 | |
var rotation_y_delta = 0.0 | |
func _unhandled_input(event): | |
if event is InputEventKey and not event.is_echo(): | |
match event.scancode: | |
KEY_A: | |
rotation_x_delta = -0.1 if event.pressed else 0.0 | |
KEY_D: | |
rotation_x_delta = 0.1 if event.pressed else 0.0 | |
KEY_W: | |
rotation_y_delta = 0.1 if event.pressed else 0.0 | |
KEY_S: | |
rotation_y_delta = -0.1 if event.pressed else 0.0 | |
$AnimationPlayer.play("Walk-loop" if rotation_x_delta or rotation_y_delta else "Idle-loop") | |
func _physics_process(delta): | |
if rotation_x_delta: | |
rotate_x(rotation_x_delta * delta) | |
if rotation_y_delta: | |
rotate_y(rotation_y_delta * delta) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment