Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- export (int) var run_speed = 300
- export (int) var jump_speed = -400
- export (int) var gravity = 1000
- var velocity = Vector2()
- var jumping = false
- func get_input():
- velocity.x = 0
- var right = Input.is_action_pressed('ui_right')
- var left = Input.is_action_pressed('ui_left')
- var jump = Input.is_action_just_pressed('ui_select')
- if jump and is_on_floor():
- jumping = true
- velocity.y = jump_speed
- if right:
- velocity.x += run_speed
- if left:
- velocity.x -= run_speed
- if left or right and jumping != false:
- get_node("AnimationPlayer").play('walkcyc')
- if left or right and jumping != true:
- $AnimatedSprite.animation = 'run'
- $AnimatedSprite.flip_h = velocity.x < 0
- if is_on_floor() and velocity.x == 0 or velocity.y == 0:
- $AnimatedSprite.animation = 'stand'
- $AnimatedSprite.flip_v = false
- $AnimatedSprite.flip_h = velocity.x < 0
- if jumping != false:
- $AnimatedSprite.animation = 'jump'
- $AnimatedSprite.flip_v = false
- $AnimatedSprite.flip_h = velocity.x < 0
- func _physics_process(delta):
- get_input()
- velocity.y += gravity * delta
- if jumping and is_on_floor():
- jumping = false
- velocity = move_and_slide(velocity, Vector2(0, -1))
Add Comment
Please, Sign In to add comment