THIS ONLY PRINTS WHAT OBJECT YOU COLLIDED WITH BUT ITS CLOSER TO THE RESULT THAN THE ABOVE CODE
extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2()
func getinput():
velocity = Vector2()
if Input.isactionpressed('uiright'):
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.isactionpressed('uidown'):
velocity.y += 1
if Input.isactionpressed('ui_up'):
velocity.y -= 1
velocity = velocity.normalized() * speed
func physicsprocess(delta):
get_input()
velocity = move_and_slide(velocity)
var collision = move_and_collide(velocity * delta)
if collision:
print("I collided with ", collision.collider.name)