SHARE
TWEET

Untitled

a guest Nov 22nd, 2015 193 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.                 set_rot(rad_up)
  20.                
  21.         if Input.is_action_pressed("move_down"):
  22.                 motion += Vector2(0, 1)
  23.                 set_rot(rad_down)
  24.  
  25.         if Input.is_action_pressed("move_right"):
  26.                 motion += Vector2(1, 0)
  27.                 set_rot(rad_right)
  28.  
  29.         if Input.is_action_pressed("move_left"):
  30.                 motion += Vector2(-1, 0)
  31.                 set_rot(rad_left)
  32.        
  33.         var velocity = speed   
  34.         if Input.is_action_pressed("run"):
  35.                 velocity = run_speed
  36.  
  37.  
  38.         motion = motion.normalized() * velocity * delta
  39.        
  40.         move(motion)
  41.  
  42. func _ready():
  43.         set_fixed_process(true)
  44.        
  45. func _fixed_process(delta):
  46.         process_movement(delta)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top