+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


enter image description here

in Engine by (49 points)
recategorized by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.