Created
December 11, 2016 19:27
-
-
Save scott-wilson/892d782c3b582503ca0b4a6eeaa642db to your computer and use it in GitHub Desktop.
Movement controller for a character
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 KinematicBody2D | |
# class member variables go here, for example: | |
# var a = 2 | |
# var b = "textvar" | |
var velocity = Vector2() | |
const WALK_SPEED = 200.0 | |
func _ready(): | |
# Called every time the node is added to the scene. | |
# Initialization here | |
set_fixed_process(true) | |
func _fixed_process(delta): | |
velocity.x = 0.0 | |
velocity.y = 0.0 | |
if (Input.is_action_pressed("ui_left") and Input.is_action_pressed("ui_right")): | |
velocity.x = 0.0 | |
elif (Input.is_action_pressed("ui_left")): | |
velocity.x = -1.0 | |
elif (Input.is_action_pressed("ui_right")): | |
velocity.x = 1.0 | |
if (Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down")): | |
velocity.y = 0.0 | |
elif (Input.is_action_pressed("ui_up")): | |
velocity.y = -1.0 | |
elif (Input.is_action_pressed("ui_down")): | |
velocity.y = 1.0 | |
var motion = velocity.normalized() * delta * WALK_SPEED | |
move(motion) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment