Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- #movimiento translates to movement.
- const speed = 10
- const gravity = 20
- const JUMP_HEIGHT = -75
- const UP = Vector2(0,-1)
- var motion = Vector2()
- func _physics_process(delta):
- printt(motion)
- motion.y += gravity
- if (Input.is_action_pressed("ui_left")):
- movimiento("left")
- if(Input.is_action_pressed("ui_right")):
- movimiento("right")
- if(Input.is_action_pressed("ui_up")):
- movimiento("up")
- if(Input.is_key_pressed("ui_up" or "ui_right" or "ui_left")):
- movimiento("nothing")
- motion = move_and_slide(motion,UP)
- func movimiento(moveset):
- match moveset:
- "left":
- $AnimatedSprite.animation = "Walking"
- $AnimatedSprite.flip_h = false
- motion.x -= speed
- "right":
- $AnimatedSprite.animation = "Walking"
- $AnimatedSprite.flip_h = true
- motion.x += speed
- "up":
- if is_on_floor():
- $AnimatedSprite.animation = "Jumping"
- $AnimatedSprite.play()
- print("On floor")
- motion.y -= JUMP_HEIGHT
- "nothing":
- if $AnimatedSprite.is_playing() == false:
- $AnimatedSprite.animation = "Idle"
- motion.x = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement