Collision causing character to teleport

Hello, I have a very annoying issue in which my character teleports when I collide with an object.

This is my code.
The weird thing is that it will teleport me if I run into 1 side of the wall, but it won’t teleport me if I run into the other side. I have no clue what to do since this is my very first Python game ever. I got this code from watching a tutorial and they had 0 problems with their collisions.

Please ask if you need more information
Thanks.

1 Like

The Bugs section is for bugs in Tiled, this is not the place to get help with your game code. Since nothing here seems specific to Tiled in any way, you’re best off posting this in the community for whatever framework you’re using (PyGame?).

Nothing in your code immediately jumps out at me as wrong, but you’ve only shown a small part of what could be causing the problem, and your description of the problem is in complete. For example, you say the character teleports, but what does that mean? Do they teleport a tile back from the wall? Beyond the wall? If they teleport beyond the wall, then the problem likely lies with how you’re updating the character’s position - your code probably thinks they’re coming at the wall from the other side because their new position is past the wall’s centre. To avoid this kind of thing in my games, I keep a copy of the previous position and use that to determine which side of a wall the character should stay on, instead of using the newly calculated position.