//remapping collision detection system
atom/proc/Collision(atom/movable/A)//algorithms
atom/movable/proc/Collided(atom/A)
atom/proc/Radius() return collisionradius
atom/proc{pxpos()return x*6416+pixel_x;pypos()return y*6416+pixel_y}
atom/var/collisionradius = 1 //make sure you can't collide with nondense
proc/CheckDist(atom/A,atom/M)
var/ax = A.pxpos() // A.x*3216+A.pixel_x//find A's centerpoint
var/ay = A.pypos() // A.y*3216+A.pixel_y
var/mx = M.pxpos() // M.x*3216+M.pixel_x//find M's centerpoint
var/my = M.pypos() // M.y*3216+M.pixel_y
var/dist = abs(sqrt((abs(axmx))^2+(abs(aymy))^2)) //based from pythagorean theorum
// world << "[dist] [A.Radius()],[M.Radius()]"
world << abs(sqrt((abs(axmx))^2+(abs(aymy))^2))
if(dist < A.Radius()+M.Radius()) return 0
else return 1
mob/Move(turf/T)
var/no = null
for(var/atom/A in range(2,src)src)
if(!CheckDist(A,src))
spawn A.Collision(src)
spawn src.Collided(A)
src << "You have collided with [A]!"
no = 1
if(!no)
if(loc)loc.Exit(src)
if(T)T.Enter(src)
if(T)src.loc = T
mob/collisionradius = 12
mob/Collided() velocity = 0
ID:148497
Jan 21 2003, 3:50 pm


I have attempted to redo Theodis's pixel based movement demo and have been stumped on the collision system. The distance formula seems to be the problem because all distance outputs seem a little small compared to the pixel coords. This system is based from pixels. (come to think of it my finding of the positions of pixel centers may be the problem! Not sure though.)

The reason your results are coming out wrong is that you used the wrong operator. You used ^ when you should have used **. In some languages, ^ is for exponentiation, but in BYOND it's for a bitwise XOR.
I wouldn't recommend using **, however, or your code's gonna be dog slow. You also don't need to use sqrt(), which will be dog slow as well. Instead, use this:
Lummox JR