Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. export var Player_id : int
  4. var motion = Vector3()
  5. export var speed = 12
  6. export var animaton_speed = 20
  7. const GRAVITY = -5
  8. const EPSILON = 0.0001
  9. var can_move = true
  10. # Called when the node enters the scene tree for the first time.
  11. func _ready():
  12.    
  13.     move_lock_y
  14.     rotation_degrees = Vector3()
  15.    
  16.     pass # Replace with function body.
  17.  
  18. func _physics_process(delta):
  19.     if can_move:
  20.         move()
  21.     fall()
  22.    
  23.    
  24.     pass
  25.    
  26. func _process(delta):
  27.    
  28.    
  29.     animate()
  30.    
  31.     pass
  32.    
  33.  
  34. func move():
  35.    
  36.     if Input.is_action_pressed("up_p%s" % Player_id) and not Input.is_action_pressed("down_p%s" % Player_id):
  37.        
  38.         motion.z = -1
  39.        
  40.         pass
  41.     elif Input.is_action_pressed("down_p%s" % Player_id) and not Input.is_action_pressed("up_p%s" % Player_id):
  42.    
  43.         motion.z = 1
  44.    
  45.     else:
  46.        
  47.         motion.z = 0
  48.    
  49.     if Input.is_action_pressed("left_p%s" % Player_id) and not Input.is_action_pressed("right_p%s" % Player_id):
  50.        
  51.         motion.x = -1
  52.     elif Input.is_action_pressed("right_p%s" % Player_id) and not Input.is_action_pressed("left_p%s" % Player_id):
  53.        
  54.         motion.x = 1
  55.    
  56.     else:
  57.         motion.x = 0
  58.        
  59.    
  60.     move_and_slide(motion.normalized() * speed, Vector3(0,1,0))
  61.  
  62.  
  63. func fall():
  64.    
  65.     if is_on_floor():
  66.        
  67.         motion.y = 0
  68.        
  69.         pass
  70.        
  71.     else:
  72.         motion.y += GRAVITY
  73.  
  74.  
  75.     pass   
  76.    
  77.    
  78. func animate():
  79.    
  80.     if not motion.z == 0 or not motion.x == 0:
  81.         if motion.length() > EPSILON:
  82.             $AnimationPlayer.play("Arms Cross Walk")
  83.         look_at(Vector3(-motion.x, 0, -motion.z) * animaton_speed, Vector3.UP)
  84.     else:
  85.         $AnimationPlayer.stop()
  86.        
  87.     pass
  88.    
  89. func can_move(can_move):
  90.    
  91.     self.can_move = can_move
  92.    
  93.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement