Advertisement
Guest User

GAMEBOX 1: SOURCE CODE player.gd

a guest
Sep 22nd, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. extends RigidBody2D
  2.  
  3. #
  4. # TODO: REMAKE THIS FOR KINEMATICBODIES TOO?
  5. #
  6.  
  7. #PHYSICS VARIABLES
  8. var SPEED = 3000
  9. var MAX_SPEED = 400
  10. var redirect_compensation = 5
  11. var direction_focus = 0.95
  12. var enabled = false
  13.  
  14. func _ready():
  15.     linear_damp = 2.3
  16.  
  17. func _physics_process(delta):
  18.    
  19.     if enabled:
  20.         if(Input.is_action_pressed("ui_left")):
  21.             linear_velocity.x -= SPEED*delta
  22.             if(linear_velocity.x > 0):
  23.                 linear_velocity.x -= SPEED*delta*redirect_compensation
  24.             linear_velocity.y *= direction_focus
  25.         if(Input.is_action_pressed("ui_right")):
  26.             linear_velocity.x += SPEED*delta
  27.             if(linear_velocity.x < 0):
  28.                 linear_velocity.x += SPEED*delta*redirect_compensation
  29.             linear_velocity.y *= direction_focus
  30.         if(Input.is_action_pressed("ui_up")):
  31.             linear_velocity.y -= SPEED*delta
  32.             if(linear_velocity.y > 0):
  33.                 linear_velocity.y -= SPEED*delta*redirect_compensation
  34.             linear_velocity.x *= direction_focus
  35.         if(Input.is_action_pressed("ui_down")):
  36.             linear_velocity.y += SPEED*delta
  37.             if(linear_velocity.y < 0):
  38.                 linear_velocity.y += SPEED*delta*redirect_compensation
  39.             linear_velocity.x *= direction_focus
  40.        
  41.     linear_velocity.x = min(max(linear_velocity.x, -MAX_SPEED), MAX_SPEED)
  42.     linear_velocity.y = min(max(linear_velocity.y, -MAX_SPEED), MAX_SPEED)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement