Created
May 8, 2017 21:34
-
-
Save inkmotor/37d5071f7d8fd924a1970cfdf6710f76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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