Colliding with walls

I’m coding an enemy npc that walks between 2 places on a 2D map and want it to walk left, hit a wall, then turn and walk right, hit a wall, and walk left again. Does anyone know how I can code this as i’ve looked at other online resources and can’t seem to find anything that works?

simple: check whether or not its collision shape hit another collision shape (in our case, the collision of the map) then when it hits just multiply its current x velocity by -1 so it will flip its horizontal direction. If you need more info about collisions:

ask if needed, glad to help!