Challenge

I have a timer to show debug stuff, it can be ignored:

extends KinematicBody2D

const SPEED = 750
const GRAVITY = 3600
const UP = Vector2(0, -1)
const JUMP_SPEED = -1750

var motion = Vector2()

func _ready():
	pass

func _physics_process(delta):
	fall(delta)
	run()
	jump()
	move_and_slide(motion, UP)
	
func fall(delta):
	if is_on_floor():
		motion.y = 0
	else:
		motion.y += GRAVITY * delta

func run():
	var direction = 0
	if Input.is_action_pressed("ui_right"):
		direction += 1
		$AnimatedSprite.flip_h = false
		$AnimatedSprite.play("run")
	elif Input.is_action_pressed("ui_left"):
		direction -= 1
		$AnimatedSprite.flip_h =true
		$AnimatedSprite.play("run")
	else:
		$AnimatedSprite.play("idle")
	motion.x = SPEED * direction
	
func jump():
	if is_on_floor() and Input.is_action_pressed("ui_up"):
		motion.y = JUMP_SPEED
	
func _on_DebugTimer_timeout():
	print(motion)
2 Likes

Privacy & Terms