• API
• FAQ
• Tools
• Archive
SHARE
TWEET Godot 2D Char Movement with Run CodeTortoise  Nov 22nd, 2015 (edited) 204 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. extends KinematicBody2D
2.
3.
4. export var speed = 200.0
5. export var run_speed = 300.0
6.
7. var rad_up = 0
8. var rad_down = PI
9. var rad_right = (PI*3)/2
10. var rad_left = PI/2
11.
12.
13.
14. func process_movement(delta):
15.         var motion = Vector2(0,0)
16.
17.         if Input.is_action_pressed("move_up"):
18.                 motion += Vector2(0, -1)
19.                 motion = motion.normalized() * speed * delta
21.
22.         if Input.is_action_pressed("move_down"):
23.                 motion += Vector2(0, 1)
24.                 motion = motion.normalized() * speed * delta
26.
27.         if Input.is_action_pressed("move_right"):
28.                 motion += Vector2(1, 0)
29.                 motion = motion.normalized() * speed * delta
31.
32.         if Input.is_action_pressed("move_left"):
33.                 motion += Vector2(-1, 0)
34.                 motion = motion.normalized() * speed * delta
36.
37.         if Input.is_action_pressed("run_up"):
38.                 motion += Vector2(0, -1)
39.                 motion = motion.normalized() * run_speed * delta
41.
42.         if Input.is_action_pressed("run_down"):
43.                 motion += Vector2(0, 1)
44.                 motion = motion.normalized() * run_speed * delta
46.
47.         if Input.is_action_pressed("run_right"):
48.                 motion += Vector2(1, 0)
49.                 motion = motion.normalized() * run_speed * delta
51.
52.         if Input.is_action_pressed("run_left"):
53.                 motion += Vector2(-1, 0)
54.                 motion = motion.normalized() * run_speed * delta
56.
57.
58.         move(motion)
59.