I am making a maze game where the player has to navigate randomly generated mazes.
The player movement (code attached below) is with the arrow keys and each time each key is pressed the player will tween a whole square in that direction (Eg. the left arrow key pressed, the player tweens - 22 px (the length of a square) on the X axis to move to the square on the left).
The problem with this is that the player has a habit of teleporting through blocks, phasing into them or shifting to the square below it when up close to them. The bizarre thing is that when the player moves up when below a hitbox they work as usual - the player is blocked therefore stays still. However, this is not the case for left, right or down. When the player is up close to a block on its left and goes left it shifts down a square and to the left, same with the right except flipped. When the player is above a block however and presses down, he teleports right through the block (sometimes multiple) and onto the square on the other side, obviously he has a tendency to move downwards.
I would like the player to not be able to do this and im wondering if it could be im using tweens instead of top down movement?
Excuse me if this issue might be a bit ridiculous but i am open to any suggestions and able to answer any queries/attemps to help me.
Thanks.
@ZeroX4 is this the code you used? Is this what i have to do to fix the issue?
@ZeroX4 Well, i copied the ‘invert the logical result’ part into my code and it fixed it so thank you!
I realized after few lines of your message you are forcing tweens without checking if tween SHOULD be played like if in direction you want to move is free or there is some obstacle
Few days ago user came to discord asking Pac-Man like logic
And this is how i made it for that user which does not allow you to go in some direction if there is obstacle ahead
So technically you 1st check can you make move and if so you tween movement
Where to check if there is obstacle i simply offset center point of player to which point inside object condition do the trick
And you need that NOT argument or however its called there