Skip to content

Instantly share code, notes, and snippets.

@willnationsdev
Last active September 13, 2019 19:30
Show Gist options
  • Save willnationsdev/8c277b089e1a3fa89382ec875a923b0a to your computer and use it in GitHub Desktop.
Save willnationsdev/8c277b089e1a3fa89382ec875a923b0a to your computer and use it in GitHub Desktop.
animation on input sample
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