Advertisement
Tyson2101

Untitled

Sep 18th, 2021
2,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. # Player Statistics Constants
  4. const UP = Vector2(0,-1)
  5. const GRAVITY = 20
  6. const MAXFALLSPEED = 300
  7. const MAXSPEED = 100
  8. const JUMPFORCE = 450
  9. const ACCEL = 50
  10.  
  11. # Movement Variables and Facing Variables
  12. var movement = Vector2()
  13. var facing_right = true
  14.  
  15. func _ready():
  16.     pass # Replace with function body.
  17.  
  18. # Any code set below this code is run 60 times a second.
  19. func _physics_process(delta):
  20.  
  21.  
  22. # Gravity Logic, for controliing how fast you fall
  23. # movement.y = movement.y + GRAVITY [This means it adds the value of GRAVITY to the movement.y variable]
  24. # If I write +=, this is the same as above. I'm just adding the number to the variable on the number or variable on the left]
  25.     movement.y += GRAVITY
  26.     if movement.y > MAXFALLSPEED:
  27.         movement.y = MAXFALLSPEED
  28.  
  29. # Facing Logics for sprite facing left or right
  30.     if facing_right == true:
  31.         $Sprite.scale.x = 1
  32.     else:
  33.         $Sprite.scale.x = -1
  34.  
  35.     movement.x = clamp(movement.x,-MAXSPEED,MAXSPEED)
  36. # Movement Controls For Character Movement
  37. # Character Moving Right
  38. # Input.is_action_pressed("right"): --- Is an action that allows me to assign keys or group of keys to this action.
  39.     if Input.is_action_pressed("right"):
  40.         movement.x += ACCEL
  41.         facing_right = true
  42.         $AnimationPlayer.play("Run")
  43. # Character Moving Left
  44.     elif Input.is_action_pressed("left"):
  45.         movement.x -= ACCEL
  46.         facing_right = false
  47.         $AnimationPlayer.play("Run")
  48. # Character Butt Smash/Ducking
  49.     elif Input.is_action_pressed("down"):
  50.         movement.x = 0
  51.         movement.y = MAXFALLSPEED
  52.         $AnimationPlayer.play("Duck")
  53. # Idle Animations and lerp
  54. # lerp changes the number of the present variables down a little
  55. # lerp(movement.x [This means the variable I want to change,0 [this is the variable I want to change to],0.2[this is how much I want it to change per 1/60th of a second.)
  56.     else:
  57.         movement.x = lerp(movement.x,0,0.2)
  58.         $AnimationPlayer.play("Idle")
  59. # Jump Movement Code
  60.     if is_on_floor():
  61.         if Input.is_action_pressed("jump"):
  62.             movement.y = -JUMPFORCE
  63.    
  64.    
  65.     if !is_on_floor():
  66.         if movement.y < 0:
  67.             $AnimationPlayer.play("Jump")
  68.         elif movement.y > 0:
  69.             $AnimationPlayer.play("Falling")
  70.        
  71.     movement = move_and_slide(movement, UP)
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement