summaryrefslogtreecommitdiff
path: root/demos/2d/kinematic_col/player.gd
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-02-22 20:28:19 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-02-22 20:28:19 -0300
commit7ca29bfaa7a23d06374c2456e0360c911bd9aa3e (patch)
treedc615e0c7a55dff92af81be0ff2555e1f9485eba /demos/2d/kinematic_col/player.gd
parentb62ec387f340220e11902daab8484fcb85d28cda (diff)
-added kinematic body
-added kinematic body demos
Diffstat (limited to 'demos/2d/kinematic_col/player.gd')
-rw-r--r--demos/2d/kinematic_col/player.gd36
1 files changed, 36 insertions, 0 deletions
diff --git a/demos/2d/kinematic_col/player.gd b/demos/2d/kinematic_col/player.gd
new file mode 100644
index 0000000000..36784a9d9f
--- /dev/null
+++ b/demos/2d/kinematic_col/player.gd
@@ -0,0 +1,36 @@
+
+extends KinematicBody2D
+
+# This is a simple collision demo showing how
+# the kinematic cotroller works.
+# move() will allow to move the node, and will
+# always move it to a non-colliding spot,
+# as long as it starts from a non-colliding spot too.
+
+
+#pixels / second
+const MOTION_SPEED=160
+
+func _fixed_process(delta):
+
+ var motion = Vector2()
+
+ if (Input.is_action_pressed("move_up")):
+ motion+=Vector2(0,-1)
+ if (Input.is_action_pressed("move_bottom")):
+ motion+=Vector2(0,1)
+ if (Input.is_action_pressed("move_left")):
+ motion+=Vector2(-1,0)
+ if (Input.is_action_pressed("move_right")):
+ motion+=Vector2(1,0)
+
+ motion = motion.normalized() * MOTION_SPEED * delta
+ move(motion)
+
+
+func _ready():
+ # Initalization here
+ set_fixed_process(true)
+ pass
+
+