Skip to content

Instantly share code, notes, and snippets.

@MarinMario
Last active July 21, 2020 16:18
Show Gist options
  • Save MarinMario/4810ef31b2e34f8eb70c5301c58bf970 to your computer and use it in GitHub Desktop.
Save MarinMario/4810ef31b2e34f8eb70c5301c58bf970 to your computer and use it in GitHub Desktop.
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