Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- # Player Statistics Constants
- const UP = Vector2(0,-1)
- const GRAVITY = 20
- const MAXFALLSPEED = 300
- const MAXSPEED = 100
- const JUMPFORCE = 450
- const ACCEL = 50
- # Movement Variables and Facing Variables
- var movement = Vector2()
- var facing_right = true
- func _ready():
- pass # Replace with function body.
- # Any code set below this code is run 60 times a second.
- func _physics_process(delta):
- # Gravity Logic, for controliing how fast you fall
- # movement.y = movement.y + GRAVITY [This means it adds the value of GRAVITY to the movement.y variable]
- # 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]
- movement.y += GRAVITY
- if movement.y > MAXFALLSPEED:
- movement.y = MAXFALLSPEED
- # Facing Logics for sprite facing left or right
- if facing_right == true:
- $Sprite.scale.x = 1
- else:
- $Sprite.scale.x = -1
- movement.x = clamp(movement.x,-MAXSPEED,MAXSPEED)
- # Movement Controls For Character Movement
- # Character Moving Right
- # Input.is_action_pressed("right"): --- Is an action that allows me to assign keys or group of keys to this action.
- if Input.is_action_pressed("right"):
- movement.x += ACCEL
- facing_right = true
- $AnimationPlayer.play("Run")
- # Character Moving Left
- elif Input.is_action_pressed("left"):
- movement.x -= ACCEL
- facing_right = false
- $AnimationPlayer.play("Run")
- # Character Butt Smash/Ducking
- elif Input.is_action_pressed("down"):
- movement.x = 0
- movement.y = MAXFALLSPEED
- $AnimationPlayer.play("Duck")
- # Idle Animations and lerp
- # lerp changes the number of the present variables down a little
- # 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.)
- else:
- movement.x = lerp(movement.x,0,0.2)
- $AnimationPlayer.play("Idle")
- # Jump Movement Code
- if is_on_floor():
- if Input.is_action_pressed("jump"):
- movement.y = -JUMPFORCE
- if !is_on_floor():
- if movement.y < 0:
- $AnimationPlayer.play("Jump")
- elif movement.y > 0:
- $AnimationPlayer.play("Falling")
- movement = move_and_slide(movement, UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement