Skip to content

Instantly share code, notes, and snippets.

@inkmotor
Created May 8, 2017 21:34
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 inkmotor/37d5071f7d8fd924a1970cfdf6710f76 to your computer and use it in GitHub Desktop.
Save inkmotor/37d5071f7d8fd924a1970cfdf6710f76 to your computer and use it in GitHub Desktop.
extends KinematicBody2D
const ACCEL = 1500
const MAX_SPEED = 500
const FRICTION = -500
const GRAV = 1000
var acc = Vector2()
var vel = Vector2()
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
acc.y = GRAV
acc.x = Input.is_action_pressed("ui_right") - Input.is_action_pressed("ui_left")
acc.x *= ACCEL
if acc.x == 0:
acc.x = vel.x * FRICTION * delta
vel += acc * delta
vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
move(vel * delta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment