2014-02-23 00:28:19 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
2017-11-12 04:53:14 +01:00
|
|
|
# This is a demo showing how KinematicBody2D
|
|
|
|
# move_and_slide works.
|
2014-02-23 00:28:19 +01:00
|
|
|
|
2015-11-21 16:13:43 +01:00
|
|
|
# Member variables
|
|
|
|
const MOTION_SPEED = 160 # Pixels/second
|
2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
|
2019-02-26 14:22:02 +01:00
|
|
|
func _physics_process(_delta):
|
2014-02-23 00:28:19 +01:00
|
|
|
var motion = Vector2()
|
|
|
|
|
2017-11-12 04:53:14 +01:00
|
|
|
if Input.is_action_pressed("move_up"):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(0, -1)
|
2017-11-12 04:53:14 +01:00
|
|
|
if Input.is_action_pressed("move_bottom"):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(0, 1)
|
2017-11-12 04:53:14 +01:00
|
|
|
if Input.is_action_pressed("move_left"):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(-1, 0)
|
2017-11-12 04:53:14 +01:00
|
|
|
if Input.is_action_pressed("move_right"):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(1, 0)
|
2014-02-23 00:28:19 +01:00
|
|
|
|
2017-11-12 04:53:14 +01:00
|
|
|
motion = motion.normalized() * MOTION_SPEED
|
2015-11-21 16:13:43 +01:00
|
|
|
|
2017-06-25 13:00:20 +02:00
|
|
|
move_and_slide(motion)
|