+1 vote

I have a 3x3 box game and I want to move the box to the empty place.
I use the walls of staticbody2d type boxes
The boxes I move are kinematicbody2d
But I have not found a suitable way to make this idea

Please help. Thank you

The code for the box that moves

extends KinematicBody2D

var vel = Vector2()
var speed = 1000
var xR = true
var xL = true
var yT = true
var yB = true

func _physics_process(delta):

if $CollisionL/Btn.pressed:
    if yT:
        translate(Vector2(0, -speed * delta))
    if yB:
        translate(Vector2(0, speed * delta))
    if xR:
        translate(Vector2(speed * delta, 0))
    if xL:
        translate(Vector2(-speed * delta, 0))
var a = move_and_collide(vel).collider.name

if a == "F2" || a == "F3" || a == "F4":
    yT = false
if a == "F6" || a == "F7" || a == "F8":
    xR = false
if a == "F10" || a == "F11" || a == "F12":
    yB = false
if a == "F13" || a == "F14" || a == "F15":
    xL = false

move_and_collide(vel)

enter image description here

asked Jul 28, 2019 in Engine by mustafamax (32 points)
recategorized Jul 28, 2019 by mustafamax

Have you tried using rays?

My God!!!
You've resolved the issue at your suggestion
Thank you

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.