Skip to content

Instantly share code, notes, and snippets.

@emersonmx
Created January 31, 2018 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersonmx/70b0e2d90251893ddb0e865dde786df6 to your computer and use it in GitHub Desktop.
Save emersonmx/70b0e2d90251893ddb0e865dde786df6 to your computer and use it in GitHub Desktop.
extends KinematicBody2D
const GRAVITY = 20
const SPEED = 300
const JUMP_HEIGHT = -600
const FLOOR_NORMAL = Vector2(0, -1)
var velocity = Vector2()
func _physics_process(delta):
velocity.y += GRAVITY
velocity.x = 0
if Input.is_action_pressed('ui_left'):
velocity.x = -SPEED
elif Input.is_action_pressed('ui_right'):
velocity.x = SPEED
if Input.is_action_just_pressed('ui_cancel'):
position = Vector2(512, 80)
velocity = Vector2()
if is_on_floor():
velocity.y += GRAVITY * 10
if is_on_floor() and Input.is_action_just_pressed('ui_select'):
velocity.y = JUMP_HEIGHT
velocity = move_and_slide(velocity, FLOOR_NORMAL, 25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment