So distance between to points is
(x2- x1)^2 + (y2-y1)^2
so if my max distance is 120 and the distance between the two points is 78.
78 < 120 = COLLISION!
No what about say...an image?
Well then you subtract the images width from the dist
distance is 150. max distance is 120
distance - imageWidth = 96 < 120 = COLLISION!
this assumes that the image has the same width and height.
How do you check for a collision with an image that has different height and width?
How do you check for a collision base on pixels?
Fast = better
currently this is what I use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public boolean collision( Vector3f other, float dist ) { if(this.loc.dist(other) > (dist*dist) ) return false; else return true;
}
public float dist( Vector3f other ) { float xd = other.x - this.x; float yd = other.y - this.y; return (xd * xd) + (yd * yd); } |