Advertisement
AstroGamesDev

Player | PuzPl

Apr 9th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. # PlayerRB.gd
  2. extends RigidBody2D
  3.  
  4. # Constants with CAPS, good practice
  5. const GRAVITY = 20
  6. const MAX_SPEED = 200
  7.  
  8. var motion = Vector2()
  9.  
  10. # A loop called every frame
  11. func _physics_process(delta):
  12.     motion.y += GRAVITY
  13.    
  14.     if Input.is_key_pressed(KEY_RIGHT):
  15.         motion.x = MAX_SPEED
  16.     elif Input.is_key_pressed(KEY_LEFT):
  17.         motion.x = -MAX_SPEED
  18.     else:
  19.         motion.x = 0
  20.    
  21.     #if is_on_floor():
  22.     #   if Input.is_action_pressed("ui_up"):
  23.     #       motion.y = JUMP_HEIGHT
  24.     #   if friction == true:
  25.     #       motion.x = lerp(motion.x, 0, 0.2) # 0.2 = 20%
  26.     #else:
  27.     #   if friction == true:
  28.     #       motion.x = lerp(motion.x, 0, 0.05) # 0.05 = 5%
  29.    
  30.     set_linear_velocity(motion)
  31.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement