Skip to content

Instantly share code, notes, and snippets.

@robeeeert
Created January 6, 2021 21:42
Show Gist options
  • Save robeeeert/92d4f529f81d9861209f51ba1d9aac64 to your computer and use it in GitHub Desktop.
Save robeeeert/92d4f529f81d9861209f51ba1d9aac64 to your computer and use it in GitHub Desktop.
Basic Godot KinematicBody movement
extends KinematicBody
export(float) var walkSpeed = 1
export(float) var rotationSpeed = 1
func _physics_process(delta):
if (Input.is_action_pressed("ui_up")):
var movement = getMovement()
move_and_slide(movement)
elif (Input.is_action_pressed("ui_down")):
var movement = getMovement() * -1
move_and_slide(movement)
if (Input.is_action_pressed("ui_right")):
global_rotate(Vector3(0,1,0), deg2rad(-rotationSpeed))
elif (Input.is_action_pressed("ui_left")):
global_rotate(Vector3(0,1,0), deg2rad(rotationSpeed))
func getMovement():
var direction = global_transform.basis.z
var movement = walkSpeed * direction
return movement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment