How do I make this 2D grid movement script work properly?

Godot Version

4.4.1

Question

Full disclaimer, I’m very new to Godot and only have a few simple game programming experiences under my belt. Basically, I was watching a YouTube video for some grid based movement system from Godot 3.5 and liked how he approached tile borders using tileset id numbers. So I decided I would fix it up and give it back to everyone in the comments section.

I have updated most of it, no errors in the script, but now I have the issue in this video. Whenever the character walks into a tile they are not supposed to (my REALLY well made water texture), instead of not being able to walk into it, they walk into it and then cant get out.

My main theory is that the script somehow defines the collision vector as the center of the character instead of the sides of it, (maybe something changed from Godot 3 to 4). Leading to the character not detecting what touches it’s sides unless it’s already on a tile it cant move from or to.

(Example of what I think the issue is.)

This is a folder with the scripts I’m using. Put movement_player.gd into a CharacterBody2D and put tile_id.gd in a TileMapLayer.

Thank you for your time!