Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Vesk |
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:
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!