Triangle/line Collision
Triangle/line Collision
Could use a hand figuring out to detect a line colliding with a triangle. The Triangle would be pointing down if that makes a difference. I wasn't sure on how to implement this because make simple hit box wont work.
What you call a bug...I call a new feature!
Re: Triangle/line Collision
https://gamedev.stackexchange.com/quest ... ction-test
For future reference, the term you wanna stick into the google machine for times like this is 'intersection'.
https://www.google.com/search?q=line+in ... Zr7teZL2Zg
For future reference, the term you wanna stick into the google machine for times like this is 'intersection'.
https://www.google.com/search?q=line+in ... Zr7teZL2Zg
Chili
Re: Triangle/line Collision
Thanks for the replies. After digging around with some of the things you guys suggested I came across this and it seems to work perfectly.
Code: Select all
lineIntersect(p0,p1,p2,p3)
{
float a1 = p1.y - p0.y;
float b1 = p0.x - p1.x;
float c1 = a1 * p0.x + b1 * po.y;
float a2 = p3.y - p2.y;
float b2 = p2.x - p3.x;
float c2 = a2 * p2.x + b2 * p2.y;
float denominator = a1 * b2 - a2 * b1;
int x = (b2 * c1 - b1 * c2) / denominator;
int y = (a1 * c2 - a2 * c1) / denominator;
return x,y;
}
What you call a bug...I call a new feature!