ID:983529
 
Keywords: collision, pixel
(See the best response by DarkCampainger.)
Hello,
I'm having issues trying to determine the nearest collision. I'm pretty new to pixel movements and basically trying to setup a Bump proc that destroys an object when it is Crossed using the Cross proc. However, If I bump in between the two it deletes both. I'm not sure how to single out the "less lined up" object so it is ignored. I'm not sure if this is even possible.
Best response
I'm not sure I understand your question (where's this second object coming from?), but bounds_dist() may be able to help you. Whichever has the lower return value for bounds_dist(Bumper, Bumpee) should theoretically be closer.
To kind of paint a picture, I'm a stick figure bumping into 2 32x32 tiles at the same point, which I believe would be the same distance. I'm not fully sure how bounds_dist() works. I would have to use bounds to get the objects I'm hitting and then use bounds_dist() to determine the nearest?
In response to WickedlyAndy
Yes, that should work. Basically, you would use for() to loop through the target types returned by bounds(), and call bounds_dist(src,target) to see how much they overlap.

If you've never found the "nearest" of something before, typically you create two variables outside of the for() loop: one to hold the closest object found so far, and one to hold that object's distance value (so "closest" and "minDist" or something). Then inside the loop, you store the bounds_dist() value in a variable, "dist". If "dist" is less than the current "minDist"--or if "closest" is null because we just started--then set "minDist" to "dist" and set "closest" to "target". Once all of the targets have been looped through, the closest one should be in "closest".

var
obj/target_type/closest
minDist

for(var/obj/target_type/target in bounds(src))
var/dist = bounds_dist(src, target)
if(!closest || dist < minDist)
minDist = dist
closest = target

world << "The closest is [closest]"