0 votes

Hi, so I've been have some real problems with the test_move() function. In this demo, I've got this T shape and it can move around in an invisible grid as well as rotate 90 degrees clockwise. It should collide with these blue walls, and when simply moving - it does. But if I try to rotate next to a wall that is to the right of the T shape (when looking from its perspective by taking into account the rotation), the T shape kinda glitches out instead of just not moving or rotating at all like it is supposed to.

This is a gif where I try to demonstrate the problem:
A gif where I try to demonstrate the problem

Here is the code attached to the T shape:

extends KinematicBody2D


func _physics_process(_delta):
    var vel = Vector2(0, 0)

    if Input.is_action_just_pressed("ui_left"):
        vel.x -= 20
    if Input.is_action_just_pressed("ui_right"):
        vel.x += 20
    if Input.is_action_just_pressed("ui_up"):
        vel.y -= 20
    if Input.is_action_just_pressed("ui_down"):
        vel.y += 20
    move_and_collide(vel)

    if Input.is_action_just_pressed("rotate") and \
            not test_move(Transform2D(global_rotation + deg2rad(90), global_position), Vector2(0, 0)):
        rotate(deg2rad(90))

And this is the whole demo project

Any help is appreciated!

in Engine by (12 points)

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.
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 webmaster@godotengine.org with your username.