Skip to content

Instantly share code, notes, and snippets.

@skeltonmod
Created November 12, 2020 06:23
Show Gist options
  • Save skeltonmod/c1ca078ec7a5e00a40460669ef9da2c8 to your computer and use it in GitHub Desktop.
Save skeltonmod/c1ca078ec7a5e00a40460669ef9da2c8 to your computer and use it in GitHub Desktop.
var y_velocity = velocity.y
var dir: Vector3 = Vector3()
if x_input != 0:
dir += camera.global_transform.basis.x * x_input
if y_input != 0:
dir += camera.global_transform.basis.z * y_input
getdirection(dir)
if not is_on_floor():
y_velocity += gravity
dir = dir.normalized() * acceleration
velocity += dir
if velocity.length() > friction:
velocity = lerp(velocity,Vector3.ZERO, friction)
else:
velocity = Vector3.ZERO
print(velocity)
velocity.y = y_velocity + gravity
if velocity.length() > speed:
velocity = velocity.normalized() * speed
velocity = move_and_slide(velocity,Vector3.UP)
if is_on_floor() or is_on_ceiling():
y_velocity = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment