Last active
July 21, 2020 16:18
-
-
Save MarinMario/4810ef31b2e34f8eb70c5301c58bf970 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 | |
var input_vector: Vector2 | |
var velocity: Vector2 | |
export var max_speed := 300 | |
export var acceleration := 500 | |
export var friction := 1000 | |
func _physics_process(delta): | |
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") | |
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") | |
input_vector = input_vector.normalized() | |
if input_vector != Vector2.ZERO: | |
velocity = velocity.move_toward(input_vector * max_speed, acceleration * delta) | |
else: | |
velocity = velocity.move_toward(Vector2.ZERO, friction * delta) | |
velocity = move_and_slide(velocity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment