This line “teleports” the duplicate to the right, so if there’s a wall to the right, it’ll be teleported into the wall. If that’s not what you want, you need to change this part. How you should change it depends what you want to happen specifically. If you describe in more detail what you want to happen, then we might be able to better help you.