I have a game where we solve the maze by swiping right and left on the road. there are walls in the game. when I swipe the character to the right, it slides in the direction I swipe until it hits the wall, and when it comes to the wall, there are sensors indicating that it touches the wall, in this way, when it receives the information that it touches the wall, it centres its position just 1 square next to the wall, that is, on the road, but sometimes this code block runs late or slowly, so it throws itself back after it gets on the wall, so when playing the game, it gives the impression that the game is running momentarily. When this happens several times in a row, it stands out too much, I couldn't solve it no matter what I did.
The bug :
youtube.com/shorts/-866PwK8D0Y
As you can see in the first and last move, it goes over the wall, but this does not happen in the others.
so the code