Well that can be fixed by upping the check, for example:
PHP Code:
while (i<dist/.5) {
onwall2(x+(dx/(dist/.5))*i,x+(dx/(dist/.5))*i),1,1);
i+=.5;
}
But that only increases the loop substantially. A simple fix would be to do a seperate check BEFORE doing the check between the two points, that involves checking for a wall in the direction of the player, but only half a tile away. If there is no wall, carry on with checking between them.