extends KinematicBody2D
const SPEED = 5
const ROTATION_SPEED = 1.5
var rotation_direction = 0
var motion = Vector2()
func _physics_process(delta):
if Input.is_action_pressed("left"):
rotation_direction = -1
elif Input.is_action_pressed("right"):
rotation_direction = 1
else:
rotation_direction = 0
if Input.is_action_pressed("up"):
motion = Vector2(0,-SPEED).rotated(rotation)
elif Input.is_action_pressed("down"):
motion = Vector2(0,SPEED).rotated(rotation)
else:
motion = Vector2()
rotation += rotation_direction * ROTATION_SPEED * delta
#this is the important part
if test_move(get_transform(),motion):
if Input.is_action_pressed("up"):
position += Vector2(0,-SPEED).rotated(rotation)
if test_move(get_transform(),motion):
motion = move_and_collide(motion)
elif Input.is_action_pressed("down"):
position += Vector2(0,SPEED).rotated(rotation)
if test_move(get_transform(),motion):
motion = move_and_collide(motion)
else:
motion = move_and_collide(motion)
else:
motion = move_and_collide(motion)
thats how i got it to work.. its pretty ugly though :(
#this is the important part
if test_move(get_transform(),motion):
if Input.is_action_pressed("up"):
position += Vector2(0,-SPEED).rotated(rotation)
if test_move(get_transform(),motion):
motion = move_and_collide(motion)
elif Input.is_action_pressed("down"):
position += Vector2(0,SPEED).rotated(rotation)
if test_move(get_transform(),motion):
motion = move_and_collide(motion)
else:
motion = move_and_collide(motion)
else:
motion = move_and_collide(motion)