Last active
August 3, 2016 13:53
-
-
Save glowcoil/71547d4577ced78b1f99026cb8cfc3b8 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
// motion_add(dir, spd): | |
vx += spd * cos(dir); | |
vy -= spd * sin(dir); | |
// setting speed to spd: | |
var current_speed; | |
current_speed = sqrt(vx*vx + vy*vy); | |
vx *= spd / current_speed; | |
vy *= spd / current_speed; | |
// friction: | |
var current_speed; | |
current_speed = sqrt(vx*vx + vy*vy); | |
if (current_speed > fric) { | |
vx *= (current_speed - fric) / current_speed; | |
vy *= (current_speed - fric) / current_speed; | |
} else if (current_speed < -fric) { | |
vx *= (current_speed + fric) / current_speed; | |
vy *= (current_speed + fric) / current_speed; | |
} else { | |
vx = 0; | |
vy = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment