Created
January 6, 2021 21:42
-
-
Save robeeeert/92d4f529f81d9861209f51ba1d9aac64 to your computer and use it in GitHub Desktop.
Basic Godot KinematicBody movement
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 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